$(document).ready(function() {
	
	Cufon.replace('h2, h2 strong, h3, h4, #unit-page-title p.date, #unit-pagination a, #unit-page-list .meta-date ');
	
/*
	$(function(){
		$.fn.supersized.options = {  
			startwidth: 1000,  
			startheight: 1000,
			vertical_center: 1,
			slideshow: 1,
			navigation: 0,
			transition: 1, //0-None, 1-Fade, 2-slide top, 3-slide right, 4-slide bottom, 5-slide left
			pause_hover: 0,
			slide_counter: 0,
			slide_captions: 0,
			slide_interval: 3000  
		};
        $('#background').supersized(); 
    });
*/


    if($("#unit-xmas-feature").length){
    	if ($.browser.msie && parseInt($.browser.version) <= 7) {
    		
    		$("#unit-xmas-feature-video").html("");
    		
    		$("#xmas-play").fadeIn("slow");
    		
    	} else {
    
	    	var player = $("#xmas-video");
	        froogaloop = $f(player[0].id);
	        
	        $("#xmas-play").fadeIn("slow");
	        
       	}
    }
    
    $("#unit-xmas-feature a").click(function(event){
		event.preventDefault();
		
		$(this).hide();
		
		if ($.browser.msie && parseInt($.browser.version) <= 7) {
		
    		$("#unit-xmas-feature-video").html('<object width="498" height="339"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=32460693&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00adef&amp;fullscreen=1&amp;autoplay=1&amp;loop=0" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=32460693&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00adef&amp;fullscreen=1&amp;autoplay=1&amp;loop=0" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="498" height="339"></embed></object>');
    		
    		$("#unit-xmas-feature-video").show();
    		
    	} else {
    		
			froogaloop.api('play');
			
			froogaloop.addEvent('finish', function(id){
				console.log('finish');
	            $("#unit-xmas-feature-video").hide();
	            $("#xmas-play").fadeIn("slow");
	        });
        }
	});
	
	


	$("#main-navigation li").hover(
		function(){
			$(this).parent().find('li').removeClass('active');
			$(this).addClass('active');
			$(this).find('ul.submenu').fadeIn(200);	
		},
		function(){
			$(this).removeClass('active');
			$(this).find('ul.submenu').fadeOut(50);	
		}
	);
	
	$("#main-navigation li ul li").hover(
		function(){
			$(this).addClass('active');
		},
		function(){		
			$(this).removeClass('active');
		}
	);
		
	
	
	$("#main-navigation").hover(
		function(){ },
		function(){
			$('#main-navigation li').removeClass('active');
		}
	);
	
	
	$('#homepage-news-list.features').cycle({ 
	    fx:     'scrollHorz', 
	    prev:   '.homepage-news-list-prev', 
	    next:   '.homepage-news-list-next', 
		speed:	'300',
	    timeout: 10000 
	});
	$('#homepage-offers-list.features').cycle({ 
	    fx:     'scrollHorz', 
	    prev:   '.homepage-offers-list-prev', 
	    next:   '.homepage-offers-list-next', 
		speed:	'300',
	    timeout: 10000 
	});
	$('#homepage-events-list.features').cycle({ 
	    fx:     'scrollHorz', 
	    prev:   '.homepage-events-list-prev', 
	    next:   '.homepage-events-list-next', 
		speed:	'300',
	    timeout: 10000
	});
	
	
	$("#unit-follow-us a").hover(
		function(){
			$('<p id="popup">'+$(this).attr('title')+'</p>').insertAfter(this);
		},
		function(){
			$('#popup').remove();
		}
	);
	
	$.fn.clear = function() {
			return this.focus(function() {
				if( this.value == this.defaultValue ) {
					this.value = "";
				}
			}).blur(function() {
				if( !this.value.length ) {
					this.value = this.defaultValue;
				}
			});
		};
	
	$('#unit-subscribe-form .text').clear();
	$('.store-search .text').clear();
	
	var animations = new Array();
	// queue all
	$("#unit-thumbnail-list li, #unit-homepage-feature .feature-list .feature-carousel").each(function() {
	    animations.push($(this));
	});

	// start animating
	if (animations.length > 0){
		doAnimation(animations.shift());
	}
	
	
	$('#unit-homepage-feature .large').animate({opacity: 1}, 500);

	function doAnimation(image) {
		if ($(image).parent().parent().attr('id') == '#unit-thumbnail-list') {
			var speed = 200;
		} else {
			var speed = 300;		
		}
	
		image.animate({ opacity: 1}, speed, function(){
	        // wait until animation is done and recurse if there are more animations
	        if(animations.length > 0) doAnimation(animations.shift());			
		});
	}
	
	
		// Begin Code for Xmas Gift Guide drop down selector
	
$('#gift-type').change(function() {
  if ($(this).val() == 'beauty') { 
     top.location="/category/christmas-gift-guide/beauty-christmas-gift-guide/"
  }
  if ($(this).val() == 'her') { 
     top.location="/category/christmas-gift-guide/her/"
  }
    if ($(this).val() == 'him') { 
     top.location="/category/christmas-gift-guide/him/"
  }
    if ($(this).val() == 'gadgets') { 
     top.location="/category/christmas-gift-guide/gadgets/"
  }
    if ($(this).val() == 'home') { 
     top.location="/category/christmas-gift-guide/home/"
  }
    if ($(this).val() == 'kids') { 
     top.location="/category/christmas-gift-guide/kids/"
  }  

});


//SBL Carousels

	$('#sbl-micro .feature-carousel.left .features').cycle({ 
	    fx:     'scrollHorz', 
	    prev:   '.prev-left', 
	    next:   '.next-left', 
		speed:	'300',
	    timeout: 10000 
	});
	
		$('#sbl-micro .feature-carousel.right .features').cycle({ 
	    fx:     'scrollHorz', 
	    prev:   '.prev-right', 
	    next:   '.next-right', 
		speed:	'300',
	    timeout: 10000 
	});

	
});
