var site_folder = "/lavoro2/";


function catalog_list_style(){
//catalog list effects
	$("#products_list li").bind("mouseover",function() {
		$(this).children().children(".product_name").addClass("product_name_over");
	}).bind("mouseout", function() {
		$(this).children().children(".product_name").removeClass("product_name_over");
	});
}
//remove jquery validate messages
$.extend($.validator.messages, {
    required: "",
    email: "",
    digits: ""
});


$(function(){
	
        Cufon.replace('#main_menu_center ul li a, #sec_menu ul li a', {fontFamily: 'DIN-Medium'});
        Cufon.replace('#main_menu_center ul li ul li a', {fontFamily: 'DIN-Regular'});
        Cufon.replace('.font-din-light', {fontFamily: 'DIN-Light'});
        Cufon.replace('.font-din-medium, .title_blue', {fontFamily: 'DIN-Medium'});
        Cufon.replace('.font-din-regular', {fontFamily: 'DIN-Regular'});
        
        $('#slider').nivoSlider({
            directionNav: false,
            pauseTime: 5000,
            afterChange: function(){
                $("#banner_mask > a").attr({"href": $("#slider > a:visible").attr("href")});
                //alert( $('#slider').data('nivo:vars').currentSlide );
            }
        });
        
        
        
        /*SAFEFORM*/
        $('.warning').remove();
        $.get( "/plugins/safeForm.php",function(txt){
          $(".secure").append('<input type="hidden" name="ts" value="'+txt+'" />');
        });
        /*SAFEFORM*/
        
        
	$(document).pngFix();
	//styles
	$("#site_lang_menu li:last").css({"border":"none"});
	
	catalog_list_style();
	
	
	//hover hacks
	
	$("#top_plogin").mouseover(function () {$(this).addClass("partner_login_hover");})
	.mouseout(function () {$(this).removeClass("partner_login_hover");});
	
	$("#top_plocator").mouseover(function () {$(this).addClass("partner_locator_hover");})
	.mouseout(function () {$(this).removeClass("partner_locator_hover");});

	$(".product_options ul li").mouseover(function () {$(this).addClass("product_options_hover");})
	.mouseout(function () {$(this).removeClass("product_options_hover");});
	
        $("a.videoPreview").fancybox({
		'hideOnContentClick': true
	});
        
        
	$("a[rel=preview]").fancybox();
	$("a[rel=wform]").fancybox({
		onStart : function() {$("#recomendForm").show();},
		onCleanup : function() {$("#recomendForm").hide();},
		autoDimensions : false,
		width:455,
		height:'auto'
	});
	$("a[rel=partnerForm]").fancybox({
		onStart : function() {$("#partner_login_box").show();},
		onCleanup : function() {$("#partner_login_box").hide();},
		autoDimensions : true/*,
		width:330,
		height:510*/
		
	});

	$('#main_menu ul').superfish({ 
		delay:         100,               
	    animation:     {opacity:'show'},   
	    speed:         'normal'         
	});
	
	//home
        /*
	$('#home_banner').coinslider({ 
		width: 900, 
		height:350,
		navigation: true, 
		delay: 8000,
		spw: 10, // squares per width
		sph: 4, // squares per height
		effect: 'rain' // random, swirl, rain, straight
	});
	*/
	
	//product icons tooltip
	
	$('.product_icons').tooltip({ 
	    track: true, 
	    delay: 0, 
	    showURL: false, 
	    showBody: " - ", 
	    extraClass: "pretty", 
	    fixPNG: true, 
	    opacity: 0.95, 
	    left: -120 
	});
	/*
	Cufon.replace('h3', {fontFamily: 'MorganBg1'});
	Cufon.replace('h2', {fontFamily: 'MorganBg1'});
	Cufon.replace('h1', {fontFamily: 'MorganBg1'});
	*/
	//$("select.sSelect").sSelect();
	
	$("#catalog_select select").change(function(){
            var type = $("#catalog_select").attr("lang");
		var options = { 
				target:$("#catalog_list"),
				url: site_folder+ "mods/store"+type+"_funcs.php",
		        type:"post",
		        success:function(data) {
					catalog_list_style();
					Cufon.replace('h2', {fontFamily: 'MorganBg1'});
		        }
		    }; 
		$("#catalog_select").ajaxSubmit(options);
	});
	
	/*
	$(".product_image").easySlider({
		nextText : "",
		prevText : "",
		controlsFade: false	
	});
*/
	
	//search product field
	$("#search_input").focus(function() {
		if($(this).val() == $(this).attr("default")){
			$(this).val("");
		}
	}).blur(function() {
		if($(this).val() == ""){
			$(this).val($(this).attr("default"));
		}
	});
	
	$("#search_submit").click(function() {
		$(this).parent().submit();
	});
	
	$("#btn_moreinfo").click(function(e){
	    var relativeX = e.pageX;
	    var relativeY = e.pageY;
	    $("#more_info_container").show().css({left:relativeX, top:relativeY});
 	});
	
	
	$("#moreinfo_form input, #moreinfo_form textarea").focus(function() {
		el = $(this);
		if(el.val() == el.attr("default")){el.val("");}
	}).blur(function() {
		el = $(this);if(el.val() == ""){el.val(el.attr("default"));}
	});
	$(".btn_close").click(function() {
		$("#more_info_container").fadeOut("slow");
	});
	/*
	$("#moreinfo_submit").click(function(){
		$("#moreinfo_form").validate({
			 errorContainer: "",
			 errorLabelContainer: "",
			 messages: {
			     moreinfo_name: "",
			     moreinfo_email: "",
			     moreinfo_message: ""
			 },
			 showErrors: function(errorMap, errorList) {
				if(this.numberOfInvalids() > 0) {
					$("#moreinfo_form_errors").show();
				}else{
					$("#moreinfo_form_errors").hide();
				}
				this.defaultShowErrors();
			}
		});
		    	  
		var options = { 
				target:$("#moreinfo_result"),
				url: site_folder+"mods/global_functions.php",
		        type:"post",
		        clearForm: true,
		        dataType : "json",
		        success:function(data) {
					$("#moreinfo_form").hide();
					$("#moreinfo_result").html(data.message).show();
					setTimeout(function() {
						$("#more_info_container").fadeOut("slow",function() {
							$("#moreinfo_form").show();
							$("#moreinfo_result").hide();	
						}); 
						
					},5000);
					
		        }
		    }; 
		if($("#moreinfo_form").valid()) {
			$("#moreinfo_form").ajaxSubmit(options);
		}
		return false;		
    });	
	*/
	
	$("#newsletter_add").focus(function() {
		el = $(this);
		if(el.val() == el.attr("default")){el.val("");}
	}).blur(function() {
		el = $(this);if(el.val() == ""){el.val(el.attr("default"));}
	});
        
        $("#newsletter_add").bind("keypress", function(e){
            if(e.keyCode == 13) {
                
                $("#newsletter_miniform").validate({
                     errorContainer: "",
                     errorLabelContainer: "",
                     messages: {
                        newsletter_add : ""
                     },
                     showErrors: function(errorMap, errorList) {
                        if(this.numberOfInvalids() > 0) {
                            $("#newsletter_error").show();
                        }else{
                            $("#newsletter_error").hide();
                        }
                        this.defaultShowErrors();
                    }
		});
		    	  
		var options = { 
                        url: site_folder+"mods/global_functions.php",
		        type:"post",
		        dataType : "json",
		        success:function(data) {
                            $("#newsletter_response").html(data.message).show();
                            setTimeout(function() {
                                $("#newsletter_response").fadeOut("slow", 
                                    function () { 
                                        $("#newsletter_add").html($("#newsletter_add").attr("default")); 
                                    });							
                            },5000);
		        }
		    }; 
		if($("#newsletter_miniform").valid()) {
                    $("#newsletter_miniform").ajaxSubmit(options);
		}
		return false;
             }
        });
        
	
	
	//$(".styledButton").css({'padding' : '3px 20px', 'font-size' : '12px'}).styledButton();
	
	$("#recomendSubmit").click(function() {
		var options = { 
			url: site_folder+"mods/global_functions.php",
	        type: "post",
	        success: function(data) {
					$("#recomend").hide();
					$("#recomend_result").show();
					setTimeout(function() {$.fancybox.close();},5000);
					
	        }
	    }; 
		if($("#recomend").valid()) {
			$("#recomend").ajaxSubmit(options);
		}
	});
	
	$("#recomend").validate({
		 errorContainer: "",
		 errorLabelContainer: "",
		 showErrors: function(errorMap, errorList) {
			if(this.numberOfInvalids() > 0) {
				$("#recomend_error_container").show();
			}else{
				$("#recomend_error_container").hide();
			}
			this.defaultShowErrors();
		}
	});
	
	$("#plogin_submit").click(function() {
		var options = { 
			url: site_folder+"mods/global_functions.php",
	        type: "post",
	        success: function(data) {
					$("#plogin_form").hide();
					$("#plogin_form_result").show();
					setTimeout(function() {$.fancybox.close();},5000);
	        }
	    }; 
		if($("#plogin_form").valid()) {
			$("#plogin_form").ajaxSubmit(options);
		}
	});
	
	$("#plogin_form").validate({
		 errorContainer: "",
		 errorLabelContainer: "",
		 showErrors: function(errorMap, errorList) {
			if(this.numberOfInvalids() > 0) {
				$("#plogin_error_container").css({color:"#ff0000"});
			}else{
				$("#plogin_error_container").css({color:"#fff"});
			}
			this.defaultShowErrors();
		}
	});
	
	//plugins forms
	
	$("#front_form, .validar").validate({
		 errorContainer: "",
		 errorLabelContainer: "",
		 showErrors: function(errorMap, errorList) {
                    if(this.numberOfInvalids() > 0) {
                            $("#error_container").show();
                    }else{
                            $("#error_container").hide();
                    }
                    this.defaultShowErrors();
		}
	});
	
});
