(function($){
$(document).ready(function(){
    $("#cforms2form").submit(function(e){
        e.preventDefault();
        dados = $(this).serialize();
        url = $(this).attr('action');
        $("#cforms2form").empty().append("<p>Enviando.. </p>");
        $.post(url, dados, function(){
                $("#cforms2form").empty().append("<p>Dados enviados com sucesso!</p>");
            });   
    });
    //$("#publicidade_header a").click(function(e){
    //    link = $(this).attr("href");
    //    $.post("http://www.revistafotografia.com.br/go", {url: link});
    //});
    
    $(".linksLateral a, #publicidade_header a, .produtoSlider ul a").click(function(e){
        e.preventDefault();
        link = $(this).attr("href");
        $.post("http://www.revistafotografia.com.br/go", {url: link}, function(){
            window.location = link;
        });
    });
    
    $("#newslForm").submit(function(e){
       e.preventDefault();
       $form = $(this);
       $form.find("input[type='submit']").attr("disabled", "disabled");
       $.post($form.attr("action"), $form.serialize(), function(cb){
            eval(cb);
            $form.find("input[type='submit']").removeAttr("disabled");
       });
    });
    $(".widg_Dic form").submit(function(e){
       e.preventDefault();
       $form = $(this);
       $form.find("input[type='submit']").attr("disabled", "disabled");
       $.post($form.attr("action"), $form.serialize(), function(cb){
        $("#dict").empty();
            eval(cb);
            $form.find("input[type='submit']").removeAttr("disabled");
       });
    });
    $("p input.email, .widg_Dic .email, .widg_Newsletter .email").focus(function(){
        if ($(this).val() == $(this).attr("defaultValue")) {
            $(this).val("");
        }
        $(this).css("color", "black");
    });
    $("p input.email, .widg_Dic .email, .widg_Newsletter .email").blur(function(){
        if ($(this).val() == "") {
            $(this).css("color", "#999");
            $(this).val($(this).attr("defaultValue"));
        } 
    });
    
    //REMOVERRRRRRRRRR
     //$(document).keypress(function(e){
     //    if (e.which == 97) {
     //        css = $("#MyCSS");
     //        newhref = css.attr("href") + "?"+ Math.random();
     //        css.attr("href", newhref);
     //    }
     //});
        
    });
        
    $(window).load(function(){
    //begin slider
	var timeOut = null;
	var timeOutPromo = null;
	var bannerPosition = [];
    bannerPosition[0] = 0;
    bannerPosition[1] = 0;
    $(".isSlider").css("height","160px");
	$slides = $(".isSlider ul");
    $slides.addClass("slides");
    $slides.css("visibility", "visible");
	var slideWidth = $slides.find("li").width();
	var slideCount = ($slides.find("li").length / $slides.length);
	var changeDelay = 2000;
	setTimeout(mudaBanner, changeDelay);
	
	var eq = 0;
    
	function mudaBanner(){
		clearTimeout(timeOut);
		bannerPosition[eq] += slideWidth;
		if (bannerPosition[eq] >= (slideWidth * slideCount))
		{
			bannerPosition[eq] = 0;
		}
        if (eq == 0) {
            eq = 1;          
        } else {
            eq = 0;       
        }

		$slides.eq(eq).stop().animate({'marginLeft':'-'+bannerPosition[eq]+'px'});
		timeOut = setTimeout(mudaBanner, changeDelay);
	}
    var bannerPositionPromo = 0;
    $slidesPromo = $(".produtoSlider ul");
    var slideWidthPromo = 275;
	var slideCountPromo = $slidesPromo.find("li").length;
    if (slideCountPromo > 1) {
        setTimeout(mudaSliderPromo, 5600);
    }
    
    function mudaSliderPromo(){
		clearTimeout(timeOutPromo);
		bannerPositionPromo += slideWidthPromo;
		if (bannerPositionPromo >= (slideWidthPromo * slideCountPromo))
		{
			bannerPositionPromo = 0;
		}
		$slidesPromo.stop().animate({'marginLeft':'-'+bannerPositionPromo+'px'});
		timeOutPromo = setTimeout(mudaSliderPromo, 5600);
	}
	//end slider
    
});
})(jQuery);
