var mainAjax_pipe;

var accordion;

var green_light=true;
var url_2 = "";
var last_url="";


//ajax --- :)
function ajax_mc_request(url) {
	
  // Zmiany do wprowadzenia
  //nie wiem czy to się da zrobić
   //document.history = url;
   //scroll page to top!!! whene aktualności więcej klick 
      var hash = document.location.href;
	  hash = hash.substr(0,hash.indexOf("#"));
	 
   // document.location.href = hash+ "#" +(Math.random()*1000)
	last_url = url;
	window.hash(url); 
	
   if(green_light!=true) {
		if(url!=url_2)return;
		setTimeout("ajax_mc_request('"+url+"')",350);
		url_2 = url;
	}

	green_light=false;
     var lnop = "wczytywanie...";
	 if(lang=="en")lnop="loading...";
	 if(lang=="ru")lnop="loading...";
	 $('panel_ajax_image').empty().addClass('ajax-loading').setHTML("<img src='ptr/img/spacer.gif' width='45' height='6' alt='' \/><i>"+lnop+"</i>");
	  $('panel_ajax_image').setStyle("z-index",9999);
	  mainAjax_pipe =  new Ajax(url.trim(), {
		method: "get",
		onCancel : function() {			
		},
		onComplete: function(){	
			 $('panel_ajax_image').empty().removeClass('ajax-loading');				    			
			  $('panel_ajax_image').setStyle("z-index",-1);
			 make_ajax_link();
  		}	,     autoCancel: true,
		update: $("content_a")
	}).request();	 
	//ajax
	//var img = "";
    // if(url.indexOf('img=')!=-1 ) img = url.substring(url.indexOf('img=')+4,url.length);
	 //setIMG(img);
     var navi = ""
     if(url.indexOf('navi=')!=-1 ) navi = url.substring(url.indexOf('navi=')+5,url.indexOf('v=')-1);
	 setNavi(navi);
	 
}


	function setIMG(img){       
		if(img.length>0) {
 			if(img.lastIndexOf('.swf')!=-1) {					
					$("img").setHTML('<div id="ufo" style="width: 314px; height:100%;">Próbuję załadować pliki	 flash</div>');  	
					var FO = { movie:"./ptrcms/uploads/"+img, width: 314, height:"100%",
						 majorversion:"7", build:"40", wmode:"transparent"};
					   UFO.create(FO, "ufo");
			} else {				
					$("img").setHTML("<img id='imageSS' src=\"./ptrcms/uploads/"+img+"\" alt=\"\" />");

			}
		}
		//else $("img").setHTML("&nbsp;");
	}

function URLDecode(psEncodeString)
{
  // Create a regular expression to search all +s in the string
  var lsRegExp = /\+/g;
  // Return the decoded string
  return unescape(String(psEncodeString).replace(lsRegExp, " "));
}

function setNavi(txt) {

	txt = URLDecode(txt);	
  var s1 = "";
  var s2 = "";
  var t = "";
  var id="";
  if(txt.indexOf('||')!=-1 ){
	s1 = txt.substring(0,txt.indexOf('||'));
	  if(s1.indexOf('~')!=-1 ){
		  id = s1.substring(0,s1.indexOf('~1'));
		  t  = s1.substring(s1.indexOf('~1')+2,s1.indexOf('~2'));
		  s1  = s1.substring(s1.indexOf('~2')+2,s1.length);
		  if(s1!="") s1= '<div class="il" onclick="return ajax_mc_request(\'txt.php?menu='+id+'&amp;navis='+s1+'&amp;tab='+t+'&amp;navi='+id+'~1'+t+'~2'+s1+'&amp;v=\');"><IMG SRC="ptr/img/m_arrow.gif" WIDTH="24" HEIGHT="12" BORDER="0" ALT="" align="ABSMIDDLE" class="il">'+s1+'</div>';
	  }
	s2 = txt.substring(txt.indexOf('||')+2,txt.length);
	 if(s2.indexOf('~')!=-1 ){
		  id = s2.substring(0,s2.indexOf('~1'));
  		  t  = s2.substring(s2.indexOf('~1')+2,s2.indexOf('~2'));
		  s2  = s2.substring(s2.indexOf('~2')+2,s2.length);
		  if(s2!="") s2= '<div class="il""><IMG SRC="ptr/img/m_arrow.gif" WIDTH="24" HEIGHT="12" BORDER="0" ALT="" align="ABSMIDDLE" class="il">'+s2+'</div>';
	  }
  } else  {
	  	s1 = txt;
	  if(s1.indexOf('~')!=-1 ){
		  id = s1.substring(0,s1.indexOf('~1'));
		  t  = s1.substring(s1.indexOf('~1')+2,s1.indexOf('~2'));
		  s1  = s1.substring(s1.indexOf('~2')+2,s1.length);
		  if(s1!="") s1= '<div class="il" onclick="return ajax_mc_request(\'txt.php?menu='+id+'&amp;tab='+t+'&amp;navis='+s1+'&amp;navi='+id+'~1'+t+'~2'+s1+'&amp;v=\');"><IMG SRC="ptr/img/m_arrow.gif" WIDTH="24" HEIGHT="12" BORDER="0" ALT="" align="ABSMIDDLE" class="il">'+s1+'</div>';
	  }	
  }

	var lnop = "strona g&#322;&#243;wna";
	 if(lang=="en")lnop="main page";
	 if(lang=="ru")lnop="стapт";
  $('navigation_pane').innerHTML = '<div class="il" onclick="window.location.href=\'index.php?ln='+lang+'\'" ><IMG SRC="ptr/img/m_arrow.gif" WIDTH="24" HEIGHT="12" BORDER="0" ALT="" align="ABSMIDDLE" >'+lnop+'</div>'+s1+s2;
}


function show_mask_img(temp_i,tyt){
		var got = temp_i.substring(temp_i.lastIndexOf('/')+1,temp_i.length);	
		 if(got.substring(0,3)=="___") {
			 temp_i = temp_i.substring(0,temp_i.lastIndexOf('/')+1)+''+got.substring(3,got.length);	
		 }
		 
		 if(got.substring(0,3)=="v__") {
			  temp_i = temp_i.substring(0,temp_i.lastIndexOf('/')+1)+''+got.substring(3,got.length-3)+'swf';	
			Mediabox.open(temp_i,tyt,'mediabox[538 370]');
			return;
		 }
// 		 alert(got+"  - "+temp_i);
       //  alert(temp_i);
   	     Lightbox.show(temp_i,tyt);
}


function make_ajax_link() {


     $$(".linktopage,.link,.imgLight,.linktoslide").removeEvents("click"); 
//	 $$("form").removeEvents("submit"); 
//	 $$(".Linktodymek").removeEvents("mouseenter"); 
//	 $$(".Linktodymek").removeEvents("mouseleave"); 

/*	 $$(".Linktodymek").addEvents({
			mouseenter: function(e){
				new Event(e).stop();    						
				$('dymek').setStyles('top:'+(e.page.y.toInt()-250)+'px; left:'+(e.page.x.toInt()+20)+'px;');
				$('dymek').setHTML("<img src='./img/ajax-loader.gif' alt='' \/>");
				$('dymek').setOpacity(1); 
				temp_tip = false;
				var url = this.getProperty('lang');	
				new Ajax(url.trim(), {

					method: 'get',
					update: $('dymek')
				}).request();			
			},
			mouseleave: function(e){
					 temp_tip = true;
					setTimeout("if(temp_tip)$('dymek').setOpacity(0);",750);
					}
	
				});	
				*/


	$$(".linktopage,.link").addEvent("click", function(e) {	
		 new Event(e).stop();    
		 ajax_mc_request(this.getProperty("lang"));		
	});

  

	 $$(".imgLight").addEvent("mouseenter", function(e) {	
		 new Event(e).stop();    
		 this.setProperty("alt","");
		 this.setProperty("title","");
	 });

	 $$(".imgLight").addEvent("click", function(e) {	
		/* new Event(e).stop();    
		 var temp_i = this.getProperty("src");
		 var got = temp_i.substring(temp_i.lastIndexOf('/')+1,temp_i.length);	
		 if(got.substring(0,3)=="___") {
			 temp_i = temp_i.substring(0,temp_i.lastIndexOf('/')+1)+''+got.substring(3,temp_i.length);	
		 }
   	     Lightbox.show(temp_i,"");
*/ new Event(e).stop();    
		 var temp_i = this.getProperty("src");
		 show_mask_img(temp_i,"");
	});

	
green_light=true;
	
	 $$('#accordion').each(function(el) {

		green_light=false;
		 accordion = new Accordion('h3.toggler', 'div.element', {alwaysHide: true,
		display: 'all-closed',
				opacity: false ,
				onActive: function(toggler, element){
					toggler.setStyle('color', '#003c7b');
				},
				onBackground: function(toggler, element){
					toggler.setStyle('color', '#686868');
				},
				onComplete: function(){		
					
					green_light=true;
				}
				}, el);
	//	 new Accordion('h3.toggler', 'div.element', el); 
	});

}






function print_me(){
		var printWin = window.open("","Print","menubar=no,toolbar=no,scrollbars=yes,resizable=yes,width=600,height=530");
		printWin.document.open();
		printWin.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html style="overflow: visible;"><head><meta http-equiv="content-type" content="text/html; charset=utf-8"/><title>Universal McCann</title><link rel="stylesheet" type="text/css" href="./css/content_style.css"/><link rel="stylesheet" type="text/css" href="./css/style.css"/></head><body style="overflow: visible; text-align:left; margin: 15px;">');
		printWin.document.write($("content_a").innerHTML);
		printWin.document.write("</body></html>");
		printWin.document.close();
		printWin.print();

}







window.addEvent('scroll',function(e){
	 $('mooquee1').setStyle('bottom',-window.getScrollTop()+'px');
});



		

	window.addEvent('load',function() {
									
									
    if(lang=="pl") {
		 $("lbCloseLink").setStyle('background',"transparent url('./ptr/img/zamknij.gif') no-repeat center");
	}
/*	setTimeout("$('dymek').setStyles('visibility: hidden; top:-300px; left:-200px;z-index: 1');",10000);
*/
			 $$('#accordion').each(function(el) {

		green_light=false;
		 accordion = new Accordion('h3.toggler', 'div.element', {alwaysHide: true,
		display: 'all-closed',
				opacity: false ,
				onActive: function(toggler, element){
					toggler.setStyle('color', '#003c7b');
				},
				onBackground: function(toggler, element){
					toggler.setStyle('color', '#686868');
				},
				onComplete: function(){					
					green_light=true;
				}
				}, el);
				
	//	 new Accordion('h3.toggler', 'div.element', el); 
	});
});
	


window.addEvent('domready', function() {
	



var obj = new mooquee($('mooquee1'));
	//$('mooquee1').setStyle('top',(Window.getHeight()-20)+'px');

// $('dymek').setStyles('visibility: visible; left:'+((Window.getWidth()/2)-272)+'px; top:'+((Window.getHeight()/2)-204)+'px; z-index: 999999;');

 
/*	 
$('dymek').addEvent("click", function(event) {
     $('dymek').setStyles('visibility: hidden; top:-300px; left:-200px;z-index: 1');
 });
 

*/

/*$$('.kwick').each(function(el,i){ 	
if(kwick_icons[i]!=null && kwick_icons[i] != "" ){
	if ( window.ie6)  {
		el.setStyle('background','url("./ptrcms/uploads/'+kwick_icons[i]+'.gif") right bottom no-repeat');
	}else {
		el.setStyle('background','url("./ptrcms/uploads/'+kwick_icons[i]+'.png") right bottom no-repeat');
	}
}
});
*/





$$(".image_zum").each(function(el)
{ 	
    var fx = new Fx.Styles(el, {duration:200, wait:false});
	el.addEvents({
		mouseenter: function(){ fx.start({"width":35,"height":20,"opacity": 1});},
		mouseleave:  function(){fx.start({"width":28,"height":16,"opacity": 0.3}).chain(function(){ $(lang).setOpacity(1);});},
		click: function(){ window.location = "index.php?ln="+el.getProperty("id"); }
	});
	if(lang!="pl") $("pl").setOpacity(.3);
	if(lang!="en") $("en").setOpacity(.3); 
	if(lang!="ru") $("ru").setOpacity(.3);
});

//var szNormal = 110, szSmall  = 90, szFull   = 219;
var szNormal = 110, szSmall  = 110, szFull   = 110;

var clicked_kwick = -1;

var kwicks = $$("#kwicks .kwick");
var fx = new Fx.Elements(kwicks, {wait: false, duration: 800, transition: Fx.Transitions.Back.easeOut});

kwicks.each(function(kwick, i) {
	kwick.addEvent("mouseenter", function(event) {
		this.setStyle('background','url("ptr/img/tlo_hover.jpg") top right no-repeat');
		this.getElement('span').setStyle('font-size','10px');
		//(this.getElement('span')).effect('font-size', {duration:400, wait:false}).start(9,11);

//		this.getElement('span').setStyle('font-weight','bold');
		this.getElement('span').setStyle('color','#fff');
		 var el = this;
		//(el.getElement('div.kwick_submenu')).effect('opacity',{duration: 200,transition: Fx.Transitions.Bounce.easeOut}).start(0,1);
		(el.getElement('div.kwick_submenu')).setOpacity(1);
		//(el.getElement('div.kwick_submenu')).effect('opacity', {duration:400, wait:false}).start(0,1);
		/*
		var o = {};
		o[i] = {width: [kwick.getStyle("width").toInt(), szFull]}
		kwicks.each(function(other, j) {
			if(i != j) {
				var w = other.getStyle("width").toInt();
				if(w != szSmall) o[j] = {width: [w, szSmall]};
				(other.getElement('div.kwick_submenu')).setOpacity(0);
			}
		});
		fx.start(o);
			*/
	});
});
 
$$("#kwicks .kwick").each( function(e,j) {
	
   e.addEvent("mouseleave", function(event) {
	var o = {};	
	var szSize = szNormal;	
	if(clicked_kwick != -1) szSize = szSmall;
	if(e.getProperty("lang")!="on") {	
		//(e.getElement('div.kwick_submenu')).effect('opacity',{duration: 400, wait:false}).start(1,0);
		(e.getElement('div.kwick_submenu')).setOpacity(0);
		/*
	if ( window.ie6)  {
		e.setStyle('background','url("./ptrcms/uploads/'+kwick_icons[j]+'.gif") right bottom no-repeat');
		} else {
		e.setStyle('background','url("./ptrcms/uploads/'+kwick_icons[j]+'.png") right bottom no-repeat');
		}
		*/
		e.setStyle('background','none');
		e.getElement('span').setStyle('font-size','9px');
		e.getElement('span').setStyle('font-weight','normal');
		e.getElement('span').setStyle('color','#89C0E9');
	}else	{		
		e.setStyle('background','url("ptr/img/tlo_clicked.jpg") top left no-repeat');
	}
		/*	
	kwicks.each(function(kwick, i) {
		if(i != clicked_kwick) {
			o[i] = {width: [kwick.getStyle("width").toInt(), szSize]};
		}
		else {
    		o[i] = {width: [kwick.getStyle("width").toInt(), szFull]};
    		(kwick.getElement('div.kwick_submenu')).setOpacity(1);
		}
	});
	fx.start(o);	
		*/
});

});


	kwicks.each(function(kwick, i) {
		kwick.addEvent("click", function(event) {      
			 clicked_kwick=i;
			 kwicks.each(function(kwick, j) {
				 if(j!=clicked_kwick){
	 				kwick.setProperty("lang","");
					(kwick.getElement('div.kwick_submenu')).setOpacity(0);
				/*	if ( window.ie6)  {
					kwick.setStyle('background','url("./ptrcms/uploads/'+kwick_icons[j]+'.gif") right bottom no-repeat');
					} else {
					kwick.setStyle('background','url("./ptrcms/uploads/'+kwick_icons[j]+'.png") right bottom no-repeat');
					}
					*/
					kwick.setStyle('background','none');
					kwick.getElement('span').setStyle('font-size','9px');
					kwick.getElement('span').setStyle('font-weight','normal');
					kwick.getElement('span').setStyle('color','#89C0E9');
					
				 } else {
					kwick.setStyle('background','url("ptr/img/tlo_clicked.jpg") top left no-repeat');
				 }
			 });
			 this.setProperty("lang","on");
		});
	});


});