// JavaScript Document
$(document).ready(function(){
    // Image Gallery Navigation
    $(".switch > li").click(function () {
        var id = $(this).attr('class');
        var number = id.charAt(3);
        // Hide Active Image Then Show The Right Image
        $(".images > div > img:not(hidden)").hide();
        $("img#" + id).show();
        // Hide Active Text Then Show The Right Text        
        $(".caption > li:not(hidden)").hide();      
        $(".cap" + number).show();      
        // Change the ID Attribute for the Selector
        $("#on").attr("id","off");
        $("." + id).attr("id","on");
    });
    // Tab Navigation for the Product Pages
    $(".tabnav > ul > li").click(function () {
        var key = $(this).attr('title');
        $('.tabnav >  ul > li').removeClass('selected');
        $(this).addClass('selected');
        if ($(this).attr('title')=='all') {
            $('.material > div').show();     
        }
        else {
            $('.material > div:visible').hide();
            $('.material > div#' + key).show();
        }
        return true;
    });
    // Show Hide feature for the Product Pages  
    $(".product-type > li > p > a.show").click(function () {
        var name = $(this).attr('name');
        $(this).text($(this).text() ==  'hide info' ? 'more info' : 'hide info');
        $("#" + name).toggle();
    });
    // Show Hide feature for the Side Menu
	$(".brand-names").hide();
    $(".sidebar-button").click(function () {
		var name = $(this).attr('name');
		$("span",this).text($("span",this).text() ==  '(+)' ? '(-)' : '(+)');
		$("." + name).toggle();
    });


	// Rotates the Images on a Timer (currently disabled)
	// setInterval(function(){switchimg();}, 7000);

	function switchimg() {
			// Determines the Number of Images to Cycle Through
			var max  = parseInt($(".switch").find('li').length);
			// Finds the visible image and records its class number
			var temp = $('.switch > li#on').attr('class');
			var num  = parseInt(temp.charAt(3));
			// Switches to the next image or jump to the start of the gallery
			if(num < max) {
				$( ".img" + (num + 1) ).trigger('click');
			}
			else if(num == max)
			{
				$( ".img" + (num - (max-1)) ).trigger('click');
			}
	}

	
});


