// JavaScript Document
// utilities javascript


// clickable DIV code
$(document).ready(function()
{
	var block = $(".teaser");
	block.click(function(){
		window.location = $(this).find("a:first").attr("href")
	});
	
	block.addClass("clickable");
	block.hover(function(){
		window.status = $(this).find("a:first").attr("href")
	}, function(){
		window.status = ""
	})
});

/*********** END ***********/


// Drop down menu code
$(document).ready(function(){

	$("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled - Adds empty span tag after ul.subnav
	
	$("ul.topnav li span").mouseover(function() { //When trigger is clicked...
		
		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click

		$(this).parent().hover(function() {
		}, function(){	
			$(this).parent().find("ul.subnav").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
		});

		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() { 
			$(this).addClass("subhover"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
	});

});

/*********** END ***********/

// Background Slideshow
 

/*********** END ***********/

// Filtering Code

(function($){

// Shuffle function from: http://james.padolsey.com/javascript/shuffling-the-dom/
    
$.fn.shuffle = function() {

        var allElems = this.get(),
            getRandom = function(max) {
                return Math.floor(Math.random() * max);
            },
            shuffled = $.map(allElems, function(){
                var random = getRandom(allElems.length),
                    randEl = $(allElems[random]).clone(true)[0];
                allElems.splice(random, 1);
                return randEl;
            });
        
        this.each(function(i){
            $(this).replaceWith($(shuffled[i]));
        });
        
        return $(shuffled);
    };
})(jQuery);
   
$(function(){
	/*       
   $(".discounted-item")
        .css("opacity","0.8")
       .hover(function(){
           $(this).css("opacity","1");
       }, function() {
           $(this).css("opacity","0.8");
       })
       .click(function(){
           location.href = $(this).attr("rel"); 
           return false;
       }) 
       
       UNCOMMENT THIS TO MAKE THE BLOCKS CLICKABLE TO THEIR REL ATTRIBUTES
       
       ;*/
       
   $("#allcat").click(function(){
       //$(".discounted-item").slideDown();
       $("#catpicker a").removeClass("current");
       $(this).addClass("current");
       return false;
   });
   
   $(".filter").click(function(){
        var thisFilter = $(this).attr("id");
        //$(".discounted-item").slideUp();
        $("."+ thisFilter).slideDown();
        $("#catpicker a").removeClass("current");
        $(this).addClass("current");
        return false;
   });
   
   //$(".discounted-item").shuffle();

});


/* ANIMATING SOCIAL MEDIA NETWORKS */
$(document).ready(function() 
{
	$('#social_nav_vertical li a').hover(function() { 
	$(this).stop().animate({ marginLeft: '20px' },300); // on Mouseover move to left
	}, function() { //on Mouseout move back to original positon
	$(this).stop().animate({ marginLeft: '0px' }, 300);
});

});

function descw()
{
	document.getElementById("social_nav_vertical").style.visibility="visible";

}

function descc()

{
	document.getElementById("social_nav_vertical").style.visibility="hidden";
}
			
/*Auto updates the scroll bar if browser resized */	

$(function()
{
	$('.scroll-pane').each(
		function()
		{
			$(this).jScrollPane(
				{
					showArrows: $(this).is('.arrow')
				}
			);
			var api = $(this).data('jsp');
			var throttleTimeout;
			$(window).bind(
				'resize',
				function()
				{
					if ($.browser.msie) {
						// IE fires multiple resize events while you are dragging the browser window which
						// causes it to crash if you try to update the scrollpane on every one. So we need
						// to throttle it to fire a maximum of once every 50 milliseconds...
						if (!throttleTimeout) {
							throttleTimeout = setTimeout(
								function()
								{
									api.reinitialise();
									throttleTimeout = null;
								},
								50
							);
						}
					} else {
						api.reinitialise();
					}
				}
			);
		}
	)

});
