jQuery().ready(function(){

	$("div.loginBox").hide();
	if ($('div.slideshow').length > 0) {
	    $('div.slideshow').cycle({
	        fx:     'fade',
	        timeout: 4000
	    });
	};

    window.setTimeout(do_masonry,2000);

    $(window).load(function() {
		do_masonry()
	});

	function do_masonry(){
	    $('.general-content').masonry({
	    	  columnWidth: 236,
	    	  itemSelector: '.content-box'
	    });
	};

	function do_masonry(){
	    $('.promoted-content').masonry({
	    	  columnWidth: 250,
	    	  itemSelector: '.content-box'
	    });
	};

	if ($('#menu li.firstLevel ul').length > 0) {
		$('#menu li.firstLevel:not(.current_ancestor):not(.current) ul').addClass('indentado');
	};

	if ($('a.fancyframe').length > 0) {
		$('a.fancyframe').fancybox({
			'width': 700,
			'height': 450,
			'autoDimensions': false,
			'autoScale': false
		});
	};

    $("#menu li.firstLevel a").click(function(e){
    	if (!$(this).attr('href') || $(this).attr('href') == '#') {
	    	e.preventDefault();
	    	$("#menu li.firstLevel ul").addClass('indentado');
	    	$(this).next('ul').toggleClass('indentado');
    	};
    	//alert($(this).attr('href'));
    });

	if ($('div.user-data-box').length > 0) {
		$('div.user-data-box').addClass('indentado');
	};

	if ($('div.isBillableDiv').length > 0) {
		if (!$("input.isBillable").attr('checked')) {
			$('div.isBillableDiv').addClass('indentado');
		} else {
			$('div.isBillableDiv').removeClass('indentado');
		};
	    $("input.isBillable").click(function(e){
	        //e.preventDefault();
	        $('div.isBillableDiv').toggleClass('indentado');
	    });
	};

	if ($('div.product-info ul.product-image-list').length > 0) {
		var w = $('div.product-info').width() - $('div.product-info ul.product-image-list').width() - 10;
		$('div.product-info h2').width(w);
	};

    $("a.user-data-confirm").click(function(){
    	$('div.user-data-box').toggleClass('indentado');
    });

	/* Efectos para los campos */
    $("input.campoInactivo, textarea.campoInactivo").focus(function(){
        $(this).toggleClass("campoActivo").toggleClass("campoInactivo");
        valorCampo = $(this).val();
        $(this).val('');
	}).blur(function(){
	   	$(this).toggleClass("campoActivo").toggleClass("campoInactivo");
        if ($(this).val() == '') $(this).val(valorCampo);
	});

   	$("input.campoError").after('<img src="/images/fielderror.png" alt="Error" class="imgError" />');

   	$("a.accessLink").click(function(e){
        e.preventDefault();
    	$("div.loginBox").toggle();
    });

   	$("a.fancyintro").click(function(e){
        e.preventDefault();
       	if ($(this).attr('href') != '#') {
       		window.top.location.href = $(this).attr('href');
       	} else {
           	parent.$.fancybox.close();
       	}
    });

   	/*

   	if($.browser.msie && $.browser.version=="6.0") {

   	} else {
		$('a.accessLink').click(function (e) {
			$('div.loginBox').modal({
				opacity: 0,
				overlayCss: {backgroundColor:"#fff"},
				overlayClose: true,
				autoPosition: false,
				maxWidth: 450,
				zIndex: 3000
			});
			return false;
		});
   	};
   	*/

    $("a.addQty").click(function(e) {
        e.preventDefault();
        var currentVal = parseInt($(this).prev("input.inputQty").val());
        if (currentVal != NaN)
        {
            $(this).prev("input.inputQty").val(currentVal + 1);
        };
    });

    $("a.closeWindow").click(function(e) {
        e.preventDefault();
        $(this).parent().hide();
    });

    $("a.removeQty").click(function(e) {
        e.preventDefault();
        var currentVal = parseInt($(this).next("input.inputQty").val());
        if (currentVal != NaN && currentVal > 1)
        {
            $(this).next("input.inputQty").val(currentVal - 1);
        };
    });

    $("a.swapImage").click(function(e) {
        e.preventDefault();
        if ($(this).hasClass('admin-image')) {
            var src = $(this).children('img').attr("src").replace("th-", "");
        } else {
            var src = $(this).children('img').attr("src").replace("50x50", "430x430");
        };
        $('div.product-info p.product-image img').attr('src', src);
    });


    $("input.cancelAccountButton").click(function(e) {
        e.preventDefault();
        if (confirm($(this).attr('alt'))) {
        	$('#cancelAccountForm').submit();
        };

    });

});

