/**
 * @author Profitroom
 */

function insertFlash(flashContainer,flashURL,flashWidth,flashHeight,flashParams,flashVars){
	if(parseInt(window.Browser.Plugins.Flash.version)<8)
		return
	if($chk($(flashContainer)))
	{
		console.log('first: '+flashContainer);
		new Swiff(flashURL,{width:flashWidth,height:flashHeight,container:$(flashContainer),vars:flashVars,params:flashParams});
	}
		
 	else
	{
		console.log('second'+flashContainer);
		window.addEvent('domready',function(){
			new Swiff(flashURL,{width:flashWidth,height:flashHeight,container:$(flashContainer),vars:flashVars,params:flashParams});
		})
	}
		
 }
 
 var mainURL;

var historyManager = new Class({
	initialize:function(baseURL,hm)
	{
		this.baseURL = new URI(baseURL).get('fragment');
		if(!this.baseURL)
			this.baseURL = new URI(baseURL);
		this.currentURL = this.baseURL;
		this.timer = this.checkForUpdates.periodical(200,this);
		this.fo = hm;
	},
	checkForUpdates:function()
	{
		currentURL = this.getURL();
		if(this.currentURL.toString()!=currentURL.toString())
			this.changeURLEvent(currentURL);
	},
	changeURLEvent:function(url)
	{
		if(url==this.baseURL.toString())
			this.changeURL('');
		else	
			this.changeURL(url);
		
	},
	changeURL:function(newURL)
	{
		this.currentURL = newURL;
		document.flash_main1.changeURL(newURL);
	},
	getURL:function()
	{
		var locationURI = new URI(location.href);
		if(locationURI.get('fragment'))
			return locationURI.get('fragment');
		if(locationURI)
			return locationURI;
	}
})

 
 function changeURL(newURL)
 {
 	var curr = getURL();
	if(getURL.toString()!=newURL.toString())
	{
		var myURI = new URI();
 		var locationURI = new URI(window.location.href);	
		window.location.href = locationURI.set('fragment',newURL);
//		this.updateContent(newURL);
	}
 }
 function getURL()
 {
 	var locationURI = new URI(location.href);
	if(locationURI.get('fragment'))
		return locationURI.get('fragment');
 }
 
//function updateContent(link){
//    var myHTMLRequest = new Request.HTML().get(link);
//    alert (myHTMLRequest);
//
//}
//
//FlashFlag = true;
//
//if(location.href.indexOf("#print")>=0) //czy ktos nadusił print page we flasu sprawdzamy
//    FlashFlag = false
////TODO: dodac w insert flashu sprawdzenie FlashFlag - jeśli jest to wyłączyć flasha na stronie do druku
//window.addEvent('domready',function(){
//    if(!FlashFlag)
//    {
//	    window.print();
//	    window.close(); //aby tylko mrugniecie storny do printa było
//    }
//});
