function d(str){try{if(console!=null)console.debug(str);}catch(e){}}
var run = new function() {
    this.version = "1.0";
    this.runArray = Array();
    this.add = function (fun) {
		this.runArray.push(fun);
    };
	 this.loadAll = function () {
        for( var i=0; i<this.runArray.length; i++ ){
			  try{this.runArray[i]();
			  		}//try
				  catch(e){d(e);
				  }//catch
				  }//for
				};
}//run
function swf(){
	var flashvars = {};
var params = {
  menu: "false",
  wmode:"opaque"
};

	swfobject.embedSWF("/flash/home01.swf", "bgPlay", "100%", "100%", "9.0.0", "expressInstall.swf", flashvars, params);
	}
function cufon(){
	//Cufon.replace('h1');
	Cufon.replace('.ptitle', { fontFamily: 'molbor' ,hover: true});
	//Cufon.replace('a.ptitle', { fontFamily: 'molbor' ,hover: true});
	Cufon.replace(".topMenu li a", { fontFamily: 'molbor' });
	Cufon.replace('.meta', { fontFamily: 'agency' });
	Cufon.replace('.stylizacjeTitle', { fontFamily: 'agency' });
	Cufon.replace('h3,h4,h5,h6', { fontFamily: 'agency' });
	}
function fokusy(){
	//alert($("#imie").attr("value"));
	$("#imie,#newsletterMail").focus(function(){
									  $(this).attr("value","");
									  })
	}
function produktyHover(){
	var ammount;
	$(" .box").each(function(index){	
										  var pos=$(this).position();
										  $(this).css({top:pos.top+'px',left:pos.left+'px'});
										  ammount=index;
										  $(this).find(".productShort").hide();
										  $(this).hover(function(){
															 	$(this).find("div.productShort").slideDown("slow");
															 	$(this).css('z-index',"1001");
																//$(this).css({z-index:"1001"});
																
																//$("body").append('<div id="maska" style="position:absolute; width:100%;height:100%; top:0px; left:0px; background:url(/images/bg_trans.png); z-index:1000;"></div>');
																$("#productList").append('<div id="maska" style="position:absolute; width:'+$("#productList").width()+'px;height:'+$("#productList").height()+'px; background:url(/images/bg_trans.png); z-index:1000;"></div>');
																
																$("#maska").css({opacity:"0"});
															
																$("#maska").animate({opacity: 0.7}, 500, function() {
																							 // Animation complete.
																						  });
															
															 },
															 function(){
															 	$(this).find("div.productShort").slideUp("fast", function(){
																																			 
																																			 });
																$("#maska").remove();
																$(this).css('z-index',"0");
															 }
															 );
										  });
  $(".box").css({position:'absolute'});
  
  var ammo=parseInt(++ammount/4);
  if(ammount%4!=0)
  		ammo++;
  else
  		ammo;
//d(ammount);
//d("reszta:"+ammount%4);

  if(ammo>0)
  		ammo=(ammo)*220;
  else
  		ammo=220;
  
  $("#productList").css({height:ammo+"px"})
  
}
function pageW(){
	//d($(document.body).width())
	if($(document.body).width()<1024)
	$("#pageW").css({"margin":'0px 10px'})
	}
	
function centerfoto(){
	$(".kolFotoBox img").each(function(index){
												 // d($(this).attr('src'));
												  //d($(this).width());
												  //d($(this).height());
												  var aa=(252-$(this).width())/2;
												  if(aa<0)
												  $(this).css({margin:'0 0 0 '+aa+'px'})
												  
												  })
	
	}
	
function tooltips(){
	$(".imgBox a ").tooltip({
									track: true, 
    delay: 0, 
    showURL: false, 
    showBody: " - ", 
    fade: 250 
									});
	
	//Cufon.replace('#tooltip h3', { fontFamily: 'agency' });
	/*
	$('.metaRow .imgBox a img').tooltip({ 
    delay: 0, 
    showURL: false, 
    bodyHandler: function() { 
        return $("<img/>").attr("src", this.src); 
    } 
});
	*/
	}
//run.add(swf);
function metamorfozyShow(){
	$("#metamorfozyShow").each(
		function(index){
										if($(this).width()<=0)
										var wid=250;
										else
										var wid= $(this).width();
										$(this).css({height:'350px',width:wid+'px',position:'relative'})
										
										var pos=$(this).position();
										$(this).find('div.pos').each(function(){
																						  $(this).css({'position':'absolute',top:'0px'});
																						  });
							});
	setTimeout("metaSwap2()", 20); 
	$(".po").css({opacity:0})
	}
function metaSwap(){
	$(".przed").animate({opacity:0 },2000);
	$(".po").animate({opacity:1 },2000);
	setTimeout("metaSwap2()", 5000); 
	}
function metaSwap2(){
	$(".przed").animate({opacity:1 },2000);
	$(".po").animate({opacity:0 },2000);
	setTimeout("metaSwap()", 5000); 
	}
function lbox(){
	//d("lb");
	$('.imgBoxx a').lightBox({txtImage:"Obraz",txtOf:"z",imageLoading:'/images/lightbox-ico-loading.gif',imageBtnClose :'/images/lightbox-btn-close.gif',imageBtnPrev:'/images/lightbox-btn-prev.gif',imageBtnNext:'/images/lightbox-btn-next.gif',imageBlank:'/images/lightbox-blank.gif'});
	$('.imgBoxx a[rel=lb1]').lightBox({txtImage:"Obraz",txtOf:"z",imageLoading:'/images/lightbox-ico-loading.gif',imageBtnClose :'/images/lightbox-btn-close.gif',imageBtnPrev:'/images/lightbox-btn-prev.gif',imageBtnNext:'/images/lightbox-btn-next.gif',imageBlank:'/images/lightbox-blank.gif'});
	$('.imgBoxx a[rel=lb2]').lightBox({txtImage:"Obraz",txtOf:"z",imageLoading:'/images/lightbox-ico-loading.gif',imageBtnClose :'/images/lightbox-btn-close.gif',imageBtnPrev:'/images/lightbox-btn-prev.gif',imageBtnNext:'/images/lightbox-btn-next.gif',imageBlank:'/images/lightbox-blank.gif'});
	$(' a[rel=blank]').attr('target','_blank');
	}

function aktualnosciSlice(){
	$("#strony-menu ul li").each(function(index){
													  if(index>8)
													  $(this).hide();
													  });
	$("#strony-menu ").append('<a id="wiecej" style="float:right; padding-top:20px; font-size:1.25em; text-transform:uppercase; letter-spacing: 0.14em; cursor:pointer;">rozwiń &gt;</a>');
	Cufon.replace('#wiecej', { fontFamily: 'molbor' ,hover: true});
	
	$("#wiecej").toggle(function()
             {
                 $("#strony-menu ul li").each(function(index){
													  $(this).show();
													  });
             },function() {
                 $("#strony-menu ul li").each(function(index){
													  if(index>8)
													  $(this).hide();
													  });
             });
	
	}


function scrollMain(){
	//d($("#center").height());	
	//$("#center").scrollable();//.navigator("#scrollNavi");
	$("#center").scrollable({circular: true, speed: 1000 }).autoscroll({ autoplay: true,interval:3000 }).navigator("#scrollNavi");

	//$("#center").scrollable();

	}

run.add(centerfoto);
run.add(cufon);
run.add(aktualnosciSlice);
run.add(metamorfozyShow);
run.add(fokusy);
run.add(pageW);
run.add(tooltips);
run.add(produktyHover);
run.add(lbox);
run.add(scrollMain);

$(document).ready(function()
				{
					run.loadAll()
				});
