$(document).ready(function(){
	/*
	//$('#nav ul li:first ul').show();
	$("a[rel^='prettyPhoto']").prettyPhoto({theme:'facebook'});
	
    $('#nav ul > li').filter(function(index) {
        $(this).each(function() {
            var $this = $(this);
            $(this).hover(function() {
                setTimeout(function() {
                    //$this.css('background-position', '-142px -' + (index * pos_bg) + 'px');
                    $this.find('a').css({'border-bottom':'9px solid #010100', 'padding-bottom':'0'});
                    $this.find('ul').fadeIn(100);
                }, 100);
            }, function() {
                setTimeout(function() {
                    //$this.css('background-position', '0px -' + (index * pos_bg) + 'px');
                    //$this.find('a').css('color', '#0066aa');
                	$this.find('a').css({'border-bottom':'0', 'padding-bottom':'9px'});
                    $this.find('ul').fadeOut(100);
                }, 100);
            });
        });
    });
    
    //set selected menu
    $selected 	= $('#nav ul li').find('a.selected');
    $parents	= $selected.parents('li');
    
    if ( $parents ) {
    	$parents.find('a').css({'border-bottom':'9px solid #010100', 'padding-bottom':'0'});
    	$selected.find('ul').fadeIn(100);
    }
    
    //main images of 1st page
    $('#promo_nav li').hover(function() {
    	var img 	= $(this).find('a').attr('rel');
    	var html 	= '<img src="' + img + '" />';
    	$('#promo_img').html( html );
	}, function() {
	});

    $('#promo_img').html( '<img src="' + $('#promo_nav li a:first').attr('rel') + '" />' );
    */

	
    
	//drop menu for profile link
    $('.prof_link').click( function() {
    	$addmenu = $('.addmenu');
    	if ( $addmenu.is(':hidden') ) {
    		$addmenu.show();
    		$(this).css('background-image', 'url(images/arrow.gif)');
    	} else {
    		$addmenu.hide();
    		$(this).css('background-image', 'url(images/arrow_back.gif)');
    	}
    	return false;
    });
    
    
    //calculator
    $('#calculator select').change( function() {
    	var Rezultat1, Rezultat2, ostatyk, Razlika, Razlika2, znak, Procent, S1, Cl1, Vs1, S2, Cl2, Vs2;
    	S1 = $("#c_o_width").val(); 
    	S2 = $("#c_n_width").val(); 
    	Cl1 = $("#c_o_lenght").val(); 
    	Cl2 = $("#c_n_lenght").val();  
    	Vs1 = $("#c_o_height").val();  
    	Vs2 = $("#c_n_height").val();  
    		
    	Rezultat1 =Cl1 * 25.4 + 2*( Vs1 *( S1/100 ) );
    	Rezultat2 =Cl2 * 25.4 + 2*( Vs2 *( S2/100 ) );
    	
    	ostatyk = ( Rezultat2 - Rezultat1 );
    	
    	if ( ( Math.abs( ostatyk ) / Rezultat1 ) * 100 > 3) {
    		$('#c_dif_d').css( {'border-color':'#CD0131', 'background-color': '#FFB9B9' } );
    	} else {
    		$('#c_dif_d').css( {'border-color':'#006600', 'background-color': '#BADCAB' } );
    	}
    	
    	if( Rezultat1 == null && Rezultat2 == null ) {
    		Razlika = 0 + "mm";
    		Razlika2 = 0 + "км/ч";
    	} else {
    		if ( ostatyk > 0 ) {
    			znak = "+";
    		} else  {
    			znak = "";
    		}
    		Razlika = ostatyk;	
    		Procent = (ostatyk*100)/Rezultat1;
    		Razlika2 =(100-Procent);
    	}
    	
    	if (Math.abs(Procent) > 3) {
    		$('#c_speed').css( { 'border-color':'#CD0131', 'background-color': '#FFB9B9' } );
    	} else {
    		$('#c_speed').css( { 'border-color':'#006600', 'background-color': '#BADCAB' } );
    	}
    	
    	$('#c_dif_d').val( znak + String( Math.round( Razlika ) ) );
    	$('#c_speed').val( Math.round( Razlika2 ) );
    	$('#c_old_d').val( Math.round( Rezultat1 ) );
    	$('#c_new_d').val( Math.round( Rezultat2 ) );
    });

    $('#calc_search').click( function() {
    	$('#calculator_form').submit();
    	return false;
    });
    
    
    //close btn fot promo window
    $('.close, #popup_box').click( function() {
		$('#popup_promo').hide();
		$('#popup_box').hide();
		setCookie('promo_10', 1, 30);
		return false;
	});
    
   
    //if ( getCookie('promo_10') != 1 ) {
    	//$('#popup_promo').show();
		//$('#popup_box').show();
    //}
		
	$('#showClientPrice a').click( function() {	
		if ( $(this).parent().find('span').is(':hidden') ) {
			$(this).parent().find('span').show();
		} else {
			$(this).parent().find('span').hide();
		}
		
		return false;
	});

});

function startBlink(){
    window.blinker = setInterval(function(){
        if(window.blink){
        	$('.blink').css('color','#108632');
           	window.blink=false;
         } else {
        	$('.blink').css('color','#ffffff');
        	window.blink = true;
         }
    },500);
}

var popUpWin=0;

function popUpWindow(URLStr, left, top, width, height)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = window.open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

function getUrlVars() {
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}

function setCookie(c_name,value,expiredays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate() + expiredays);
	document.cookie=c_name+ "=" +escape(value)+ ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookie(c_name) {
	if (document.cookie.length>0) {
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1) {
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			
			if (c_end==-1) {
				c_end=document.cookie.length;
			}
			return unescape(document.cookie.substring(c_start,c_end));
	    }
	}
	return "";
}
