$(document).ready(function() {

(function($){
  $.fn.shuffle = function() {
    return this.each(function(){
      var items = $(this).children();
      return (items.length)
        ? $(this).html($.shuffle(items))
        : this;
    });
  }
 
  $.shuffle = function(arr) {
    for(
      var j, x, i = arr.length; i;
      j = parseInt(Math.random() * i),
      x = arr[--i], arr[i] = arr[j], arr[j] = x
    );
    return arr;
  }
})(jQuery);


var flashvars;
var params = {
wmode:"transparent"
};
var attributes;
	
	/* Home Page slider */
		
		var numCategories = $("ul.FeaturedCategories li").length;
		
		//shuffle the cat LIs
		//$("ul.FeaturedCategories").shuffle();
		//make the cat LIs have the correct identifiers
		$("ul.FeaturedCategories li").each(function(it){
			$(this).attr('id','img'+(it+1));
			$(this).find('a').attr('rel',(it+1));
		});
	
		var extended = $('li#img1');
		$(extended).addClass('extended');
		var startTitle = 0;
		$('.CategoriesBox li').each(function(){
			if($(this).is(":animated"))
			{
				isAnimated = true;
			}
		});
		
		$("ul.FeaturedCategories li a").click(function(e){
			if(!$(this).parent().is('.extended') && !$(this).parent().is("span") && !$(this).parent().is(".carousel_link2"))
			{
				e.preventDefault();
			}
		})
		$("ul.FeaturedCategories li div span").each(function() {
			if(!$(this).parent().parent().is("#img1")) {
				$(this).hide();
			}
		});
		
		function sliderMove (el) {
			var mover = $(el);
			var isAnimated = false;
			var numCategories = $("ul.FeaturedCategories li").length;
			extended = $("li.timg.extended");
			
			
			
			if($(el).attr('id') != $(extended).attr('id')) {
					$(extended).find("span").fadeOut("fast",function() {
						$(mover).animate({width:'423px'},"slow",function() {
							$(mover).find("span").fadeIn("slow");
					});
					$(extended).animate({width:'84px'},"slow",function() {
						$("ul.FeaturedCategories").animate({left: -($(mover).position().left)},"slow",function(){
							currentOrder = parseInt($(mover).find('a').attr('rel'));
							$("ul.FeaturedCategories li").each(function(i){
								if(parseInt($(this).find('a').attr('rel')) < currentOrder)
								{
									y = parseInt($(this).find('a').attr('rel')) + numCategories;
									$(this).find('a').attr('rel',y);
									$("ul.FeaturedCategories").css('left',0);
									$(this).appendTo("ul.FeaturedCategories");
									if($(this).find('a').attr('rel') > startTitle) {
										startTitle = $(this).find('a').attr('rel');
									}
								}
							}).each(function(i){
								$(this).css('z-index',startTitle-i);
							})
						});
					});
					$(extended).removeClass('extended');
					extended = mover;
					$(extended).addClass('extended');
				});
			}
		}
		
		$('.CategoriesBox li').click(function() {
			if($(this).attr('Class') == "carousel_link2")
				sliderMove($(this).parent().parent().parent().parent());	
			
			else
				sliderMove($(this));
		});
		

		window.autoSlideTimer = window.setInterval(function(){sliderMove($("li.timg.extended").next())},4000);
		
		$("div#viewport").hover(function(){
			window.clearInterval(window.autoSlideTimer);
		},function(){
			window.autoSlideTimer = window.setInterval(function(){sliderMove($("li.timg.extended").next())},4000);
		})
		


		/* See inside function on item pages */
		
		$("a.seeInside").click(function (){
			if($(this).is('.Open')) {
				$("div.seeInsideWidget").fadeOut("fast");
				$("span.blueblock").parent().show("fast");
				$(this).removeClass("Open");
				$('div.social').css('bottom','17px');
				return false;
			}else{		
				$("div.seeInsideWidget").fadeIn("fast");
				$("span.blueblock").parent().hide("fast");
				$(this).addClass("Open");
				$('div.social').css('bottom','17px');
				return false;
			}
		
		});
		$("a.seeInsideClose").click(function(){$("div.seeInsideWidget").fadeOut("fast");
		$("span.blueblock").parent().show("fast")
		$("a.seeInside").removeClass("Open");
		return false;
		});
}); /* ends document ready function */	



/* See Inside Slider */
$(window).ready(function () {
	var currentthumb = 1;
	var thumbwidth = 0;
	var totalthumbs = 0;
	var moveto = 0;
	if (navigator.appName == "Microsoft Internet Explorer") {
	} else{
	l_change = 4;
	}
	
	$(".seeInsideWidget a.right").click(function(){
		jQuery.easing.def = "easeOutExpo";
		var thumbwidth = $("div.thumbs ul li").outerWidth() + l_change;
		var totalthumbs = $("div.thumbs ul li").size();
		var moveto = 0;
		moveto = currentthumb * thumbwidth
		
			if(currentthumb <= totalthumbs - 7 ){
				$("a.right").fadeIn('fast');
				$(".thumbs ul").animate({left: '-' + moveto +'px'}, 500, "swing");
				currentthumb = currentthumb + 1;
			
				return false;
			}else{
				$("a.right").fadeOut('fast');
				return false
			}
		

	});
	$(".seeInsideWidget a.left").click(function(){
			$("a.right").fadeIn('fast');
			$(".thumbs ul").animate({left: '0px'}, 700, "swing");
			currentthumb = 1;
			return false;
		
	});
});/* ends window ready function */

