/*
*	Site Namespace
*/
var Mendoza = {};

Mendoza.Main = function() {
    this.init();
};

Mendoza.Main.prototype = function() {
    // var private methods
    var over = function(el) {
        // cache current overview
        var currentOverview = $(el).attr('class');

        if (this.defaultImage.queue().length > 0) // check queue for  default image animations
        {
            this.defaultImage.stop({ clearQueue: true }); // stop animation ( clear queue)
            var dOpacity = this.defaultImage.css('opacity'); // cache opacity
            this.defaultImage.css('opacity', 1).hide(); // reset default image
            $('img.' + this.overview).stop({ clearQueue: true }).css('opacity', 1).hide(); // stop animation (clear queue) and reset overview animation
            $('img.' + currentOverview).css('opacity', dOpacity); // set current overview opacity
        }
        else // no animations in queue
        {
            this.defaultImage.fadeOut('slow'); // do normal default image fade out
        }

        $('img.' + currentOverview).show().fadeTo('slow', 1); // animate current overview

        this.overview = currentOverview; // set current overview
    };

    var out = function(el) {
        $('img.' + this.overview).fadeOut('slow');
        this.defaultImage.fadeIn('slow');
    };

    return {
        init: function() {
            // cache elements
            this.triggers = $('#categorylinkcontainer a');
            this.defaultImage = $('#overviewcontainer img.default');

            // set up methods
            this.attachEvents();
        },

        attachEvents: function() {
            var thisClass = this;
            this.triggers.hover(
				function() { over.call(thisClass, this) },
				function() { out.call(thisClass, this) }
			);
        }
    };
} ();

Mendoza.enableHomeNav = function() {

    //hide all homenav sub items if Javascript is enabled
    $("#homenav > ul > li > div.content").hide();

    //map toggle function to LI rollover
    $("#homenav > ul > li").hover(function() {
        $(this).addClass("selected");
        $(this).children("div.content").show();
    },
	function() {
	    $(this).removeClass("selected");
	    $(this).children("div.content").hide();
	});
};

/* Rollover script */
Mendoza.enableRollovers = function() {
    $("img.rollover").hover(function() {
        $(this).attr("src", $(this).attr("src").split(".").join("_roll."));
    },
	function() {
	    $(this).attr("src", $(this).attr("src").split("_roll.").join("."));
	});
};

/* Slideshow rollover script (needed because of PNG fix) */
Mendoza.enableSlideshowRollovers = function() {
    $("#slideshowcontainer1 img#prevpage").hover(function() {
        $(this).attr("src", "/images/btn_slideshow_prev_roll.png");
    },
	function() {
	    $(this).attr("src", "/images/btn_slideshow_prev.png");
	});
	$("#slideshowcontainer1 img#nextpage").hover(function() {
        $(this).attr("src", "/images/btn_slideshow_next_roll.png");
    },
	function() {
	    $(this).attr("src", "/images/btn_slideshow_next.png");
	});

	//For other containers
	$("#slideshowcontainer2 img#prevpage, #slideshowcontainer3 img#prevpage,#slideshowcontainer4 img#prevpage,#slideshowcontainer5 img#prevpage,#slideshowcontainer6 img#prevpage,#slideshowcontainer7 img#prevpage").hover(function() {
	    $(this).attr("src", "/images/btn_slideshow_prev_roll.png");
	},
	function() {
	    $(this).attr("src", "/images/btn_slideshow_prev.png");
	});
	$("#slideshowcontainer2 img#nextpage, #slideshowcontainer3 img#nextpage,#slideshowcontainer4 img#nextpage,#slideshowcontainer5 img#nextpage,#slideshowcontainer6 img#nextpage,#slideshowcontainer7 img#nextpage").hover(function() {
	    $(this).attr("src", "/images/btn_slideshow_next_roll.png");
	},
	function() {
	    $(this).attr("src", "/images/btn_slideshow_next.png");
	});
};

/* Slideshow script */
Mendoza.enableSlideshow = function() {
    // Since javascript is enabled, show the paging controls
    $("#slideshowcontainer1 #controls").show();

    // Hide all the slides, then show the first one
    $("#slideshowcontainer1 #slideshow div.slide").hide();
    $("#slideshowcontainer1 #slideshow div:first-child").show();

    // Get the number of slides and start the count at zero
    var total1 = $("#slideshowcontainer1 #slideshow div.slide").size();
    var count1 = 1;

    // Set the initial values of the counter display
    $("#slideshowcontainer1 #totalpages").text(total1);
    $("#slideshowcontainer1 #curpage").text(count1);

    // Counting up
    $("#slideshowcontainer1 #controls #nextpage").click(function() {
    $("#slideshowcontainer1 #slideshow div:nth-child(" + count1 + ")").hide();
        count1++;
        if (count1 > total1) {
            count1 = 1;
        }
        $("#slideshowcontainer1 #slideshow div:nth-child(" + count1 + ")").show();
        $("#slideshowcontainer1 #curpage").text(count1);
    });

    // Counting down
    $("#slideshowcontainer1 #controls #prevpage").click(function() {
    $("#slideshowcontainer1 #slideshow div:nth-child(" + count1 + ")").hide();
        count1--;
        if (count1 < 1) {
            count1 = total1;
        }
        $("#slideshowcontainer1 #slideshow div:nth-child(" + count1 + ")").show();
        $("#slideshowcontainer1 #curpage").text(count1);
    });

    //for container2

    // Since javascript is enabled, show the paging controls
    $("#slideshowcontainer2 #controls").show();

    // Hide all the slides, then show the first one
    $("#slideshowcontainer2 #slideshow div.slide").hide();
    $("#slideshowcontainer2 #slideshow div:first-child").show();

    // Get the number of slides and start the count at zero
    var total2 = $("#slideshowcontainer2 #slideshow div.slide").size();
    var count2 = 1;

    // Set the initial values of the counter display
    $("#slideshowcontainer2 #totalpages").text(total2);
    $("#slideshowcontainer2 #curpage").text(count2);

    // Counting up
    $("#slideshowcontainer2 #controls #nextpage").click(function() {
        $("#slideshowcontainer2 #slideshow div:nth-child(" + count2 + ")").hide();
        count2++;
        if (count2 > total2) {
            count2 = 1;
        }
        $("#slideshowcontainer2 #slideshow div:nth-child(" + count2 + ")").show();
        $("#slideshowcontainer2 #curpage").text(count2);
    });

    // Counting down
    $("#slideshowcontainer2 #controls #prevpage").click(function() {
        $("#slideshowcontainer2 #slideshow div:nth-child(" + count2 + ")").hide();
        count2--;
        if (count2 < 1) {
            count2 = total2;
        }
        $("#slideshowcontainer2 #slideshow div:nth-child(" + count2 + ")").show();
        $("#slideshowcontainer2 #curpage").text(count2);
    });


    //for container3

    // Since javascript is enabled, show the paging controls
    $("#slideshowcontainer3 #controls").show();

    // Hide all the slides, then show the first one
    $("#slideshowcontainer3 #slideshow div.slide").hide();
    $("#slideshowcontainer3 #slideshow div:first-child").show();

    // Get the number of slides and start the count at zero
    var total3 = $("#slideshowcontainer3 #slideshow div.slide").size();
    var count3 = 1;

    // Set the initial values of the counter display
    $("#slideshowcontainer3 #totalpages").text(total3);
    $("#slideshowcontainer3 #curpage").text(count3);

    // Counting up
    $("#slideshowcontainer3 #controls #nextpage").click(function() {
        $("#slideshowcontainer3 #slideshow div:nth-child(" + count3 + ")").hide();
        count3++;
        if (count3 > total3) {
            count3 = 1;
        }
        $("#slideshowcontainer3 #slideshow div:nth-child(" + count3 + ")").show();
        $("#slideshowcontainer3 #curpage").text(count3);
    });

    // Counting down
    $("#slideshowcontainer3 #controls #prevpage").click(function() {
        $("#slideshowcontainer3 #slideshow div:nth-child(" + count3 + ")").hide();
        count3--;
        if (count3 < 1) {
            count3 = total3;
        }
        $("#slideshowcontainer3 #slideshow div:nth-child(" + count3 + ")").show();
        $("#slideshowcontainer3 #curpage").text(count3);
    });

    //for container4

    // Since javascript is enabled, show the paging controls
    $("#slideshowcontainer4 #controls").show();

    // Hide all the slides, then show the first one
    $("#slideshowcontainer4 #slideshow div.slide").hide();
    $("#slideshowcontainer4 #slideshow div:first-child").show();

    // Get the number of slides and start the count at zero
    var total4 = $("#slideshowcontainer4 #slideshow div.slide").size();
    var count4 = 1;

    // Set the initial values of the counter display
    $("#slideshowcontainer4 #totalpages").text(total4);
    $("#slideshowcontainer4 #curpage").text(count4);

    // Counting up
    $("#slideshowcontainer4 #controls #nextpage").click(function() {
        $("#slideshowcontainer4 #slideshow div:nth-child(" + count4 + ")").hide();
        count4++;
        if (count4 > total4) {
            count4 = 1;
        }
        $("#slideshowcontainer4 #slideshow div:nth-child(" + count4 + ")").show();
        $("#slideshowcontainer4 #curpage").text(count4);
    });

    // Counting down
    $("#slideshowcontainer4 #controls #prevpage").click(function() {
        $("#slideshowcontainer4 #slideshow div:nth-child(" + count4 + ")").hide();
        count4--;
        if (count4 < 1) {
            count4 = total4;
        }
        $("#slideshowcontainer4 #slideshow div:nth-child(" + count4 + ")").show();
        $("#slideshowcontainer4 #curpage").text(count4);
    });

    //for container5

    // Since javascript is enabled, show the paging controls
    $("#slideshowcontainer5 #controls").show();

    // Hide all the slides, then show the first one
    $("#slideshowcontainer5 #slideshow div.slide").hide();
    $("#slideshowcontainer5 #slideshow div:first-child").show();

    // Get the number of slides and start the count at zero
    var total5 = $("#slideshowcontainer5 #slideshow div.slide").size();
    var count5 = 1;

    // Set the initial values of the counter display
    $("#slideshowcontainer5 #totalpages").text(total5);
    $("#slideshowcontainer5 #curpage").text(count5);

    // Counting up
    $("#slideshowcontainer5 #controls #nextpage").click(function() {
        $("#slideshowcontainer5 #slideshow div:nth-child(" + count5 + ")").hide();
        count5++;
        if (count5 > total5) {
            count5 = 1;
        }
        $("#slideshowcontainer5 #slideshow div:nth-child(" + count5 + ")").show();
        $("#slideshowcontainer5 #curpage").text(count5);
    });

    // Counting down
    $("#slideshowcontainer5 #controls #prevpage").click(function() {
        $("#slideshowcontainer5 #slideshow div:nth-child(" + count5 + ")").hide();
        count5--;
        if (count5 < 1) {
            count5 = total5;
        }
        $("#slideshowcontainer5 #slideshow div:nth-child(" + count5 + ")").show();
        $("#slideshowcontainer5 #curpage").text(count5);
    });

    //for container6

    // Since javascript is enabled, show the paging controls
    $("#slideshowcontainer6 #controls").show();

    // Hide all the slides, then show the first one
    $("#slideshowcontainer6 #slideshow div.slide").hide();
    $("#slideshowcontainer6 #slideshow div:first-child").show();

    // Get the number of slides and start the count at zero
    var total6 = $("#slideshowcontainer6 #slideshow div.slide").size();
    var count6 = 1;

    // Set the initial values of the counter display
    $("#slideshowcontainer6 #totalpages").text(total6);
    $("#slideshowcontainer6 #curpage").text(count6);

    // Counting up
    $("#slideshowcontainer6 #controls #nextpage").click(function() {
        $("#slideshowcontainer6 #slideshow div:nth-child(" + count6 + ")").hide();
        count6++;
        if (count6 > total6) {
            count6 = 1;
        }
        $("#slideshowcontainer6 #slideshow div:nth-child(" + count6 + ")").show();
        $("#slideshowcontainer6 #curpage").text(count6);
    });

    // Counting down
    $("#slideshowcontainer6 #controls #prevpage").click(function() {
        $("#slideshowcontainer6 #slideshow div:nth-child(" + count6 + ")").hide();
        count6--;
        if (count6 < 1) {
            count6 = total6;
        }
        $("#slideshowcontainer6 #slideshow div:nth-child(" + count6 + ")").show();
        $("#slideshowcontainer6 #curpage").text(count6);
    });

    //for container7

    // Since javascript is enabled, show the paging controls
    $("#slideshowcontainer7 #controls").show();

    // Hide all the slides, then show the first one
    $("#slideshowcontainer7 #slideshow div.slide").hide();
    $("#slideshowcontainer7 #slideshow div:first-child").show();

    // Get the number of slides and start the count at zero
    var total7 = $("#slideshowcontainer7 #slideshow div.slide").size();
    var count7 = 1;

    // Set the initial values of the counter display
    $("#slideshowcontainer7 #totalpages").text(total7);
    $("#slideshowcontainer7 #curpage").text(count7);

    // Counting up
    $("#slideshowcontainer7 #controls #nextpage").click(function() {
        $("#slideshowcontainer7 #slideshow div:nth-child(" + count7 + ")").hide();
        count7++;
        if (count7 > total7) {
            count7 = 1;
        }
        $("#slideshowcontainer7 #slideshow div:nth-child(" + count7 + ")").show();
        $("#slideshowcontainer7 #curpage").text(count7);
    });

    // Counting down
    $("#slideshowcontainer7 #controls #prevpage").click(function() {
        $("#slideshowcontainer7 #slideshow div:nth-child(" + count7 + ")").hide();
        count7--;
        if (count7 < 1) {
            count7 = total7;
        }
        $("#slideshowcontainer7 #slideshow div:nth-child(" + count7 + ")").show();
        $("#slideshowcontainer7 #curpage").text(count7);
    });

};

$(document).ready(function() {
    new Mendoza.Main();
    //	Mendoza.enableHomeNav();
    Mendoza.enableSlideshow();
    Mendoza.enableRollovers();
    Mendoza.enableSlideshowRollovers();
    $("#searchbox").coolinput();
});