var refreshTime=25;
var descrMovement;
var prod1Change;
var mainRotateTime=10000;
var shown1=0;
var shown2=1;

function Buttons(){
    inputs = document.getElementsByTagName('input');
    for(i = 0; i < inputs.length; i++){
        if(inputs[i].type != 'image')
        inputs[i].className='input';
        if(inputs[i].type == 'submit')
        inputs[i].className='button';
    }
}
function Init(){
   // Buttons();
    /**
    * wyłączamy autocomplete zeby nie kolidowac z hintami ajaxowymi
    * _i_ zachowac zgodnosc z xhtml
    */
    var s = document.getElementById('search_query_words');
	 if (s)
    s.setAttribute("autocomplete", "off");
}

function imageScale(sender, max_size) {
    p=0;
    if (sender.width > max_size) {
        p = (max_size / sender.width);
    }
    else {
        if (sender.height > max_size) {
            p = (max_size / sender.height);
        }
    }
    if(p > 0) {
        sender.width = p * sender.width;
    }
}


function searchOver (what) {
    document.getElementById(what).className = 'HintHighlight';
    showHints();
}
function searchOut (what) {
    document.getElementById(what).className = 'HintUnHighlight';
}
function searchDown (str) {
    document.getElementById('search_query_words').value = str;
}
var timeout=1000;
var oldQuery='';
function hintMe() {
    query=document.getElementById('search_query_words').value;
    /*hint.className='searchDivHidden';*/
    document.getElementById('searchHint').style.visibility='visible';
    if (query != oldQuery) {
        oldQuery=query;
        if (query && query.length>3) {
            window.setTimeout('xajax_searchHints(query);',timeout);
        } else {
            hideHints();
        }
    }
}
function showHints() {
    query=document.getElementById('search_query_words').value;
    if (query && query.length>3) {
        hint=document.getElementById('searchHint');
        if (hint.style.visibility!='visible') hint.style.visibility='visible';
    }
}
function hideHints() {
    hint=document.getElementById('searchHint');
    hint.style.visibility='hidden';
}
function auto_off() {
if (s)
    alert(s.toString);
}

function hide_list(list)
{
    list.style.display='none';
}

function show_list(list)
{
    list.style.display='block';
}

function visible(list)
{
    if ((list.style.display=='block') || list.style.display=='')
    return true;

    return false;
}

function _$(id)
{
    return document.getElementById(id);
}

function ShowBox(id, ms, timer) {
    var timer=(timer==null) ? 0 : timer;
    var objref=document.getElementById(id);

    var scrOfX = 0, scrOfY = 0;
    if( typeof( window.pageYOffset ) == 'number' ) {
        //Netscape
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        //DOM
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        //IE6
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }
    //  wysrodkowanie w pionie
    var topBoxOffset=scrOfY+(screen.availHeight/3)-(objref.offsetHeight/2);
    //	wysrodkowanie w poziomie
    var leftBoxOffset=scrOfX+(screen.availWidth/2)-(objref.offsetWidth/2);

    objref.style.top=topBoxOffset+"px";
    objref.style.left=leftBoxOffset+"px";
    if (timer < ms) {
        objref.style.display="block";
        timer+=10;
        setTimeout("ShowBox('"+id+"',"+ms+","+timer+")",1);
    } else {

        objref.style.display="none";

    }
}

function zagielCheckOrderValue(value, message) {
    if (value < 100) {
        window.alert(message);
        return false;
    } else {
        return true;
    }
}

function zagielProductCalcLink(shopNo, value, message) {

    if (zagielCheckOrderValue(value, message)) {
        window.open('https://www.zagiel.com.pl/kalkulator/index_smart.php?action=getklientdet_si_rata&shopNo='+shopNo+'&goodsValue='+value,'Policz_rate','width=630,height=500,directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no');
    }
}

/* zmiana zdjecia na stronie glownej */
function stopProd1(){
	clearInterval(prod1Change);	
}
function startProd1(){
	prod1Change = window.setInterval("rotateProd1()", mainRotateTime);
}

function rotateProd1(){
	var infoImgs1=$("#bestSellerAll .rotate");
	var infoCount=infoImgs1.length;
	var shown=$("#bestSellerAll > div").index( $(".rotate:visible")[0] );

  	if (shown==-1){
		shown=0;
	}
	else{
		infoImgs1.eq(shown1).css({display:"none"});
		infoImgs1.eq(shown2).css({display:"none"});
		shown1+=2;
		shown2+=2;
		if (shown1>=infoCount)
			shown1-=infoCount;
		if (shown2>=infoCount)
			shown2-=infoCount;
//		alert(shown1+" "+shown2);
	}
	if($.browser.msie && parseInt($.browser.version) <= 6){
		infoImgs1.eq(shown1).css({display:"block",left:"205px",top:"25px"});
		infoImgs1.eq(shown2).css({display:"block",left:"512px",top:"25px"});	
	}
	else{
		infoImgs1.eq(shown1).css({display:"block",left:"200px",top:"25px"});
		infoImgs1.eq(shown2).css({display:"block",left:"505px",top:"25px"});
	}

}


/* funkcja poczatkowa */
$().ready(function()
	{
	
		var rotateProd=$("#bestSellerAll .rotate");
			if (rotateProd.length>1){
				/*rotateProd1.eq(0).css({visibility:"visible"});*/
				rotateProd1();
				startProd1();
				$("#bestSellerAll").hover(function(e) {stopProd1()},function(e) {startProd1()} );
			
			}
		  if($.browser.msie && parseInt($.browser.version) <= 7){	
/*		  		$("#category").hover(function(){$("#bestSellerAll > div").css({"display":"none"}); },function(){$("#bestSellerAll > div").css({"display":""}); });*/
		  		$("#categTop").add("#category").clone().appendTo("#ieHelper");
				$("#leftCol").empty();
		  }	
		
	});