$(document).ready(function() {

    $(".roll").each(function() {
        rollsrc = $(this).attr("src");
        rollON = rollsrc.replace(/.png$/ig, "_over.png");
        $("<img>").attr("src", rollON);
    });

    $(".roll").mouseover(function() {
        imgsrc = $(this).attr("src");
        matches = imgsrc.match(/_over/);
        if (!matches) {
            imgsrcON = imgsrc.replace(/.png$/ig, "_over.png");
            $(this).attr("src", imgsrcON);
        }
    });

    $(".roll").mouseout(function() {
        $(this).attr("src", imgsrc);
    });

    $("div.viewOrder img").click(function(){
        $("div.viewOrder div#orderToAdd").show();
    });

    $("#itemSubmit").click(function() {
        $("#orderToAdd div.form").hide();
        $("#orderToAdd div.status").show();
        
        myObject = {
            'id' : $("input#itemId").val(),
            'subItemSelected' : $("#subItemSelected").val(),
            'itemAmount' : $("input#itemAmount").val()
        }

        $("#orderToAdd div.status").load('./index.php?folder=shop&action=add', myObject, function() {
            alert('Producto agregado a la cesta correctamente.');
            $("#orderToAdd div.status").hide();
            $("#orderToAdd div.form").show();
        });

    });
    
    $("div.categoryList").click(function(){
        window.location = $(this).find("a").attr("href");
        return false;
    });

   $("div.slideItem").click(function(){
        window.location = $(this).find("a").attr("href");
        return false;
    });
    
   $("div.offerList2").click(function(){
        window.location = $(this).find("a").attr("href");
        return false;
    });

    if ($("#sliderNovedades").length > 0) {
        $("#sliderNovedades").easySlider({
			auto: false,
			continuous: true,
			nextId: "slider1nextNovedades",
			prevId: "slider1prevNovedades"
		});
	}

    if ($("#sliderOfertas").length > 0) {
        $("#sliderOfertas").easySlider({
			auto: false,
			continuous: true,
			nextId: "slider1nextOfertas",
			prevId: "slider1prevOfertas"
		});
	}

    if ($("#sliderMarcas").length > 0) {
        $("#sliderMarcas").easySlider({
			auto: true,
                        speed: 1000,
                        pause: 4000,
			continuous: true,
			nextId: "slider1nextMarcas",
			prevId: "slider1prevMarcas"
		});
	}

    $().piroBox({
        my_speed: 600, //animation speed
        bg_alpha: 0.5, //background opacity
        radius: 4, //caption rounded corner
        scrollImage : false, // true == image follows the page, false == image remains in the same open position
        pirobox_next : 'piro_next', // Nav buttons -> piro_next == inside piroBox , piro_next_out == outside piroBox
        pirobox_prev : 'piro_prev',// Nav buttons -> piro_prev == inside piroBox , piro_prev_out == outside piroBox
        close_all : '.piro_close',// add class .piro_overlay(with comma)if you want overlay click close piroBox
        slideShow : 'slideshow', // just delete slideshow between '' if you don't want it.
        slideSpeed : 4 //slideshow duration in seconds(3 to 6 Recommended)
    });

    $(".menuList").click(function() {
       $(this).child(".menuSubList").show();
    });

    $(".menuParentShow").parent().show();

    $("#showTheMenu").ready(function() {
       $("#category_" + $("#showTheMenu").html()).show();
    });

    $(".changeImageItem").click(function() {
        $(".viewImage").css('background', '#fff url(\'./images/shop/item/thumbs/' + $(this).attr('title') + '\') no-repeat center center');
        $(".viewImage").children('a').attr('href', './images/shop/item/' + $(this).attr('title'));
    });
});
