function imageHoversInit()
{	
	$$('a.image-hover').each(function(el){
			var imgs = el.getChildren();
			var active = el.getAttribute('name');
			var img = new Asset.image(active);
			var inactive = imgs[0].getAttribute('src');
			el.addEvent('mouseenter', function(){ imgs[0].setAttribute('src', active); });
			el.addEvent('mouseleave', function(){ imgs[0].setAttribute('src', inactive); });
	});	
}

function changePerpageList( e, href )
{
	window.location.href = href+'&perPage='+e.value;
}

function P7_HScroller(el,dr,tx,ox,spd) { //v1.6 by PVII
 var g,gg,fr,sp,pa='',slw=true,m=false,w,ww,lx,rx;tx=parseInt(tx);
 if((g=MM_findObj(el))!=null){gg=(document.layers)?g:g.style;}else{return;}
 if(dr=="Stop"){if(g.toMove){clearTimeout(g.p7Magic);}g.toMove=false;}
 if((parseInt(navigator.appVersion)>4 || navigator.userAgent.indexOf("MSIE")>-1)&& !window.opera){pa="px";}
 if(navigator.userAgent.indexOf("NT")>-1 || navigator.userAgent.indexOf("Windows 2000")>-1){slw=false;}
 if(spd=="Slow"){sp=(slw)?2:1;fr=(slw)?40:30;}else if(spd=="Medium"){sp=(slw)?4:1;fr=(slw)?40:10;
 }else{sp=(slw)?8:4;fr=(slw)?40:10;}if(spd=="Warp"){sp=5000;}var xx = parseInt(gg.left);if(isNaN(xx)){
 if(g.currentStyle){xx=parseInt(g.currentStyle.left);}else if(document.defaultView){
 xx=parseInt(document.defaultView.getComputedStyle(g,"").getPropertyValue("left"));}else{xx=0;}}
 if(document.all || document.getElementById){w=parseInt(g.offsetWidth);if(!w){w=parseInt(g.style.pixelWidth);}
 if(g.hasChildNodes){for(wx=0;wx<g.childNodes.length;wx++){ww=parseInt(g.childNodes[wx].offsetWidth);
 if(ww>w){w=ww;}}}}else if(document.layers){w=parseInt(g.clip.width);}lx=tx-w+parseInt(ox);rx=tx;
 if(dr=="Right"){if(xx>lx){m=true;xx-=sp;if(xx<lx){xx=lx;}}}
 if(dr=="Left"){if(xx<rx){m=true;xx+=sp;if(xx>rx){xx=rx;}}}
 if(dr=="Reset"){gg.left=tx+pa;if(g.toMove){clearTimeout(g.p7Magic);}g.toMove=false;}
 if(m){gg.left=xx+pa;if(g.toMove){clearTimeout(g.p7Magic);}g.toMove=true;
  eval("g.p7Magic=setTimeout(\"P7_HScroller('"+el+"','"+dr+"',"+tx+","+ox+",'"+spd+"')\","+fr+")");
 }else{g.toMove=false;}
}

function popImage(imageURL,imageTitle){
	
defaultWidth  = 500;
defaultHeight = 500;

var AutoClose = true;

// Do not edit below this line...
// ================================
if (parseInt(navigator.appVersion.charAt(0))>=4){
var isNN=(navigator.appName=="Netscape")?1:0;
var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight;
var optIE='scrollbars=no,width=150,height=100';
	
if (isNN){imgWin=window.open('about:blank','',optNN);}
if (isIE){imgWin=window.open('about:blank','',optIE);}
with (imgWin.document){
writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');
writeln('<sc'+'ript>');
writeln('var isNN,isIE;')
;writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
writeln('isNN=(navigator.appName=="Netscape")?1:0;');
writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
writeln('function reSizeToImage(){');
writeln('if (isIE){');
writeln('window.resizeTo(100,100);');
writeln('width=100-(document.body.clientWidth-document.images[0].width)+20;');
writeln('height=100-(document.body.clientHeight-document.images[0].height);');
writeln('window.resizeTo(width,height);}');
writeln('if (isNN){');       
writeln('window.innerWidth=document.images["George"].width;');
writeln('window.innerHeight=document.images["George"].height+19;}}');
writeln('function doTitle(){document.title="'+imageTitle+'";}');
writeln('</sc'+'ript>');
if (!AutoClose) writeln('</head><body topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0" bgcolor=FFFFFF scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
else writeln('</head><body topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0" bgcolor=FFFFFF scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
writeln('<img name="George" src='+imageURL+' style="display:block"></body></html>');
close();		
}
}

function o(identyfikator) {
	return document.getElementById(identyfikator);
}

function str_replace (search, replace, subject, count) {
    // http://kevin.vanzonneveld.net
    var i = 0,
        j = 0,
        temp = '',
        repl = '',
        sl = 0,
        fl = 0,
        f = [].concat(search),
        r = [].concat(replace),
        s = subject,
        ra = Object.prototype.toString.call(r) === '[object Array]',
        sa = Object.prototype.toString.call(s) === '[object Array]';
    s = [].concat(s);
    if (count) {
        this.window[count] = 0;
    }

    for (i = 0, sl = s.length; i < sl; i++) {
        if (s[i] === '') {
            continue;
        }
        for (j = 0, fl = f.length; j < fl; j++) {
            temp = s[i] + '';
            repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
            s[i] = (temp).split(f[j]).join(repl);
            if (count && s[i] !== temp) {
                this.window[count] += (temp.length - s[i].length) / f[j].length;
            }
        }
    }
    return sa ? s : s[0];
}
		
function getVisibleHeight(Width, Height) {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return myHeight;
}

function openPage(theUrl,W,H){
    var theWin ="'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width="+W+",height="+H+"'"
	littleWin = window.open(theUrl,'',theWin);
	//littleWin.resizeTo(W+10,H+29);
 	littleWin.focus();
}

function newsletterAdd(){
	
	var form = document.forms['form_newsletter'];
	var email = form.newsletter_email.value;
	
	if(validateEmail(email)){
		if (form.rules.checked == false){
			alert('Zaznacz klauzurę o przechowywaniu danych osobowych');
		}
		else
		{
			form.form_type.value = 'add';
			form.submit();
		}		
	}
	else{
		alert('Niepoprawny adres e-mail');
	}
}

function newsletterDel(){
	
	var form = document.forms['form_newsletter'];
	var email = form.newsletter_email.value;
	
	if(validateEmail(email)){
		form.form_type.value = 'del';
		form.submit();
	}
	else{
		alert('Niepoprawny adres e-mail');
	}
}


/*********************************************************/
/* Web Pages Menu                                        */
/*********************************************************/

function hideAllSubMenuMshop(level){

	if ( level == 0 )
	{
		var hrefObj = $$('.menu_a');
		if (hrefObj[0] == null ) return;
		hrefObj[0].className = 'menu_i';
		var selectObj = hrefObj[0].getNext();
	}
	else if ( level == 1 )
	{
		var hrefObj = $$('div .menu_sa');
		if (hrefObj[0] == null ) return;
		hrefObj[0].className = 'menu_si';
		var selectObj = hrefObj[0].getNext();
	}
	else
	{
		var hrefObj = $$('div .menu_ssa');
		if (hrefObj[0] == null ) return;
		hrefObj[0].className = 'menu_ssi';
		var selectObj = hrefObj[0].getNext();
	}

	if (selectObj == null) return;
	selectObj.style.display = "none";

}

function showSubMenu(obj){

	var selectObj = document.getElementById( obj );
	if (selectObj==null)	return;

	if (selectObj.style.display != ""){
		selectObj.style.display = "";
	}
	else
		selectObj.style.display = "none";

	return;
}

function showSubMenuMshop(catName, hrefName, level){

	var selectObj = $(catName);
	var hrefObj = $(hrefName);
	if (selectObj==null)	return;

	if (selectObj.style.display != ""){

        if ($(catName) != null)
        	hideAllSubMenuMshop(level);

		selectObj.style.display = "";
		if ( level == 0 )
			hrefObj.className = 'menu-shop-active';
		else if ( level == 1 )
			hrefObj.className = 'menu-shop-sub-active';
		else if ( level == 2 )
			hrefObj.className = 'menu-shop-sub-sub-active';
		else
			hrefObj.className = 'menu-shop-sub-sub-sub-active';
	}
	else {

        if ($(catName) != null)
        	hideAllSubMenuMshop(level);

        selectObj.style.display = "none";

		if ( level == 0 )
			hrefObj.className = 'menu-shop-inactive';
		else if ( level == 1 )
			hrefObj.className = 'menu-shop-sub-inactive';
		else if ( level == 2 )
			hrefObj.className = 'menu-shop-sub-sub-inactive';
		else
			hrefObj.className = 'menu-shop-sub-sub-sub-inactive';		
	}



	return;
}

function hideSubMenu(obj){

	if ( obj!="" ){
		var selectObj = document.getElementById( obj );

		if (selectObj != null)
			selectObj.style.display = "none";
	}
}

function highSubItem(obj){

	if ( obj!="" ){
		var selectObj = document.getElementById( obj );

		if (selectObj != null){
			if(selectObj.className=='menu_i')
				selectObj.className='menu_a';

			if(selectObj.className=='menu_si')
				selectObj.className='menu_sa';

			if(selectObj.className=='menu_top_i')
				selectObj.className='menu_top_a';
		}
	}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


function validateEmail(string) {
	
	if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
		return true;
	else
	return false;
}

function validateCartDel(idPro){
	var form = document.forms['cart'];
	var zatwierdz = true;

	var delid = 'del_'+idPro;
	$(delid).value = idPro;
	
	form.form_cart_order.value = 0;
	
	var CartId = document.getElementsByName("cart_id[]");
	 
	if (zatwierdz){
		form.submit();
 	}
}


function validateCart(type){
	var form = document.forms['cart'];
	var zatwierdz = true;

	if(type=="order") form.form_cart_order.value = 1;
	else form.form_cart_order.value = 0;
	
	var CartId = document.getElementsByName("cart_id[]");
	 
	if (zatwierdz){
		form.submit();
 	}
}

function otherPlaceChange()
{
	var form = document.shipment;
	
	if (form.delivery_other.checked)
		$('delivery-place').setStyle('display', '');
	else
		$('delivery-place').setStyle('display', 'none');
}

var curPos;

function moveToFrame(id)
{
	var frame = 'id_'+id;
	fx.toElement(frame);
	
	var link = 'pager-link-'+id;
	curPos = id;
	$('pager-link-1').set('class',''); 
	$('pager-link-2').set('class','');
	$('pager-link-3').set('class','');
	$('pager-link-4').set('class','');
	$('pager-link-5').set('class','');
	
	$(link).set('class','active-pager');
}

function moveToFrameTime(id)
{
	if (curPos!=0)
	{
		id = curPos;
		curPos = 0;
	}
	//alert(curPos);
	var frame = 'id_'+id;
	fx.toElement(frame);
	
	//alert(id);
	if (id==5) var nextFrame = 1;
	else var nextFrame = id+1;
	
	var link = 'pager-link-'+id;
	
	$('pager-link-1').set('class',''); 
	$('pager-link-2').set('class','');
	$('pager-link-3').set('class','');
	$('pager-link-4').set('class','');
	$('pager-link-5').set('class','');
	
	$(link).set('class','active-pager');
	setTimeout("moveToFrameTime("+nextFrame+")", 4000);
}

function ShowMenu(cat_id)
{
	//alert(cat_id);
	var sub_cat_id = 'sub_'+cat_id;
	var arr = $$("div.sub_cat");

	arr.each(function(item){
		item.setStyle('display', 'none');
		
	})
	
	$(sub_cat_id).setStyle('display', '');
	setHeightSubCat(sub_cat_id);
	
	var div_cat_id = 'cat_'+cat_id;
	var arr2 = $$(".menu-shop-active");
	arr2.each(function(item){
		item.set('class', 'menu-shop-inactive');
	})
	
	//$$('#myElement a.myClass');
	$(div_cat_id).set('class', 'menu-shop-active set-rel');
}

function HideMenu(cat_id)
{
	//alert(cat_id);
	var sub_cat_id = 'sub_'+cat_id;
	var arr = $$("div.sub_cat");

	arr.each(function(item){
		item.setStyle('display', 'none');
		
	})
	
/*	$(sub_cat_id).setStyle('display', '');
	setHeightSubCat(sub_cat_id); */
	
	var div_cat_id = 'dcat_'+cat_id;
	var arr2 = $$(".menu-shop-active");
	arr2.each(function(item){
		item.set('class', 'menu-shop-inactive');
	})
	
	/*$(div_cat_id).set('class', 'menu-shop-active set-rel');*/
}

function setManufacturer() {
	var idMan = $('id_man_main').value;
	var searchHref = $('search-href').value;
	window.location.href = searchHref + '&id_man=' + idMan;
}

function CompareSubmit(idPro) {
	
	$('delCompare').value = idPro;
	document.forms['com_list'].submit();
}

function CompareDelete() {
	
	$('delCompareAll').value = 'all';
	document.forms['com_list'].submit();
} 

function ResetContent()
{
	var arr2 = $$(".cat-sub-all");
	arr2.each(function(item){
		item.set('style', 'display:none;');
	})
}

function ShowCatContent(id)
{
	ResetContent();
	
	var cat_id = 'cats_'+id;
	
//	alert(cat_id);
	
	$(cat_id).setStyle('display', '');
}

function setDesc(type)
{
    var div = $('div_'+type);
    var span = $('span_'+type);
    div.setStyle('display', 'block');
    span.setStyle('font-weight', 'bold');

    if (type == 'other')
    {
        div = $('div_fromcat');
        span = $('span_fromcat');
        if ($defined(div)) div.setStyle('display', 'none');
        if ($defined(span)) span.setStyle('font-weight', '100');

        div = $('div_most');
        span = $('span_most');
        if ($defined(div)) div.setStyle('display', 'none');
        if ($defined(span)) span.setStyle('font-weight', '100');
        
        var gallery5 = new slideGallery($("gallery"), {
    		steps: 4,
    		mode: "circle",
    		autoplay: true,
    		duration: 5000
    	});
    }
    else if (type == 'fromcat')
    {
        div = $('div_other');
        span = $('span_other');
        if ($defined(div)) div.setStyle('display', 'none');
        if ($defined(span)) span.setStyle('font-weight', '100');

        div = $('div_most');
        span = $('span_most');
        if ($defined(div)) div.setStyle('display', 'none');
        if ($defined(span)) span.setStyle('font-weight', '100');
        
    }
    else
    {
        div = $('div_other');
        span = $('span_other');
        if ($defined(div)) div.setStyle('display', 'none');
        if ($defined(span)) span.setStyle('font-weight', '100');

        div = $('div_fromcat');
        span = $('span_fromcat');
        if ($defined(div)) div.setStyle('display', 'none');
        if ($defined(span)) span.setStyle('font-weight', '100');
        
        var gallery5 = new slideGallery($("gallery3"), {
    		steps: 4,
    		mode: "circle",
    		autoplay: true,
    		duration: 5000
    	});
    }
}

function moveBg(item)
{
	var big_id = 'big_pic_'+item.get('id').substring(9,10);
	
	$$('.big_pic').each(function(item){
		item.setStyle('display','none');
	});
	
	$(big_id).setStyle('display','block');
	
	$$('.small_pic').each(function(item){
		item.removeClass('active');
	});
	
	item.addClass('active');
	
	$(big_id).setStyle('display','block');
}

function moveBgIn(item,src)
{
	var bgSrc = src+'/img/pro_img_bg.gif';
	item.setStyle('background','url('+bgSrc+') top left no-repeat');
}

function moveBgOut(item)
{
	item.setStyle('background','');
}


