/*----------------------------------------------------------------------
[Store Javascript]
Fashion Rocks Store specific scripts

Copyright:		Great Fridays 2010
Client:			Fashion Rocks
Project:		E-Commerce
Created by:		Adam Foster
Date created:	08-03-2011			
-----------------------------------------------------------------------*/

/* Fashion Rocks > replace fonts --------------------------------------*/

Cufon.replace('.post h3, .post h2, .post-list h3, .sidebar-post-list h3', { fontFamily:'HelveticaNeueLT Com 75 Bd' });

/* When the dom is ready... -------------------------------------------*/

jQuery(document).ready(function() {
});

/* Events landing > hotspot link rollovers ----------------------------*/

function hotSpotLinks(){
	
	jQuery('.hot-link').each(function() { var o = new linkMe(jQuery(this)); });
	
	function linkMe(e) {
	
		var o = {
			init : function() {
				o.link = jQuery(e);
				o.href = o.link.attr('href');
				o.title = o.link.attr('title');
				o.col = jQuery(e).parents('li');
				o.monitor();
			}, 
			monitor : function() {
				o.col.attr('title', o.title);
				o.col.addClass('linkCol').click(function() {
					window.location = o.href;								 
				});
				o.col.hover(function(){
					o.col.find('.eventBorder').stop().animate({bottom: 0}, 100, 'easeInOutQuad');	
				},function(){
					o.col.find('.eventBorder').stop().animate({bottom: -6}, 100, 'easeInOutQuad');	
				});
			}
		};
		o.init();
		
	};
	
};

/* Events > scrolling content --------------------------------------*/

function galleryScroller() {
	
	var itemsCount = jQuery('#light-scroller > ul').length,
		scroller = jQuery('#light-scroller'),
		current = 0,
		itemsWidth = 380,
		info = jQuery('.photo-pag em'),
		next = jQuery('.nextButton'),
		prev = jQuery('.prevButton');
	
	if(itemsCount > 1) {
		next.click(function(){ stepRight(); });
		prev.click(function(){ stepLeft(); });	
	};
	
	function stepRight(){
		if(next.hasClass('disabled')) return false;
		if(prev.hasClass('disabled')) prev.removeClass('disabled');
		current++;
		update();
		
	};
	
	function stepLeft(){
		if(prev.hasClass('disabled')) return false;
		if(next.hasClass('disabled')) next.removeClass('disabled');
		current--;
		update();
	};
	
	function update(){
		scroller.stop().animate({left: -(itemsWidth * current)}, 300, 'easeInOutQuad');
		info.html(current+1 + ' of ' + itemsCount);
		if(current==0){ 
			prev.addClass('disabled'); 
		}else if(current+1==itemsCount){
			next.addClass('disabled'); 
		};
		Cufon.refresh();
	};
	
};

/* Events > scrolling content -----------------------------------------------------------------------*/
/* Dependencies - jquery tools scrollable */

function scrollerSetUp(obj,vis) {
	
	var o = {
		
		/* INIT: Run scroller functions & selector caching */
		
		init : function() {
			o.scroller = jQuery(obj);	
			o.moving = false;
			o.thumbsApi = null;
			if(o.scroller.find('li').length <= 4) return false;
			o.scroller.children('.mask').before("<a href='javascript:void(0);' class='slider-left'>Left</a>").after("<a href='javascript:void(0);' class='slider-right'>Right</a>");
			o.leftButton = jQuery('.slider-left', o.scroller);
			o.rightButton = jQuery('.slider-right', o.scroller);
			o.addScroll();	
			o.rightButton.click(function(){
				if(o.moving==true) { 
					return false; 
				}else {
					o.thumbsApi.next();
				}
			});	
			o.leftButton.click(function(){
				if(o.moving==true) { 
					return false; 
				}else {
					o.thumbsApi.prev();
				}
			});					
		},
		
		/* ADDSCROLL: setup scroller */
		
		addScroll : function() {				
			
			/* Set up scoller  */
			o.thumbsApi = o.scroller.scrollable({
				clickable: false,
				keyboard: false,
				items: o.scroller.find('ul'),
				loop: true,
				speed: 350,
				size: vis,
				onBeforeSeek: function(){
					o.moving = true;
				},
				onSeek: function(){
					o.moving = false;
				}
			}).circular({ api: true });
			
		}
		
	};
	
	o.init();
	return o.thumbsApi;
	
};

/* TV - info toggle -----------------------------------------------------------------------------*/

function infoToggle(){

	jQuery('#video-details').each(function() { var o = new toggle(jQuery(this)); });
	
	function toggle(e){
				
		var o = {
			init : function() {
				o.content = jQuery(e);
				o.selected = false;
				o.content.css('right',-260);
				o.trigger = o.content.siblings('.infoButton');
				o.trigger.click(function() {
					o.monitor();			 
				});
			}, 
			monitor : function() {
				if(o.selected == false){
					o.trigger.html('close');
					o.trigger.addClass('closeButton');
					o.content.stop().animate({right: 0}, 200, 'easeInOutQuad');
					o.selected = true;
				}else {
					o.trigger.html('info');
					o.trigger.removeClass('closeButton');
					o.content.stop().animate({right: -260}, 200, 'easeInOutQuad');
					o.selected = false;					
				};
			}
		};
		o.init();
		
	};
	
};

/* Video hotspots  ------------------------------------------------------------------------------*/

function videoHover() {
	jQuery('.video-lists li a').each(function () {
		var scrollItem = jQuery(this);
		var sOver = scrollItem.children('.over');
		scrollItem.hover(
			function() {
				browser == 'ie' ? sOver.css({'display':'block'}) : sOver.stop().animate({opacity: 1}, {duration:250,easing:'easeInOutQuad'});
			},
			function() {
				browser == 'ie' ? sOver.css({'display':'none'}) : sOver.stop().animate({opacity: 0}, {duration:250,easing:'easeInOutQuad'});
			}
		);
		browser == 'ie' ? sOver.css({'display':'none'}) : sOver.css({'opacity':0,'display':'block'});
	});
	
};

/* Music hotspots  ------------------------------------------------------------------------------*/

function musicHotSpots() {
	
	jQuery('#music-feature li').each(function () {
		
		var gItem = {
			obj: jQuery(this),
			enabled: true,
			loaded: false,
			init: function ()
			{
				gItem.content = gItem.obj.children('a').fadeOut(0);
				gItem.overlay = gItem.content.children('.over');
				
				gItem.lineObj = jQuery("<div class='line'></div>").fadeTo(0,0);
				gItem.flashObj = jQuery("<div class='flash'></div>").fadeTo(0,0);
				gItem.obj.append(gItem.flashObj,gItem.lineObj);
				
				gItem.content.children('img').bind('load', gItem.onImageLoaded);
				var source = gItem.content.children('img').attr('src');
					gItem.content.children('img').attr('src','');
					gItem.content.children('img').attr('src',source);
			},
			addToStage : function () {
				gItem.overlay.hide();
				gItem.obj.children('a').hide();
				gItem.obj.removeClass('loaded');
				gItem.flashObj.fadeTo(0, 0);
				if(gItem.loaded){
					gItem.flash();
				}
			},
			onMouseOver : function (){
				gItem.lineObj.stop().animate({height: 6, opacity: 1}, 100, 'easeInOutQuad');
				browser == 'ie' ? gItem.overlay.show() : gItem.overlay.stop().fadeTo(200,1);
			},
			onMouseOut : function (){
				gItem.lineObj.stop().animate({height: 0, opacity: 0}, 100, 'easeInOutQuad');
				browser == 'ie' ? gItem.overlay.hide() : gItem.overlay.stop().fadeOut(180, "easeOutQuad");
			},
			onImageLoaded : function(){
				gItem.loaded = true;
				gItem.flash();
			},
			flash : function(){
				var delayTime = (Math.random() * 800);
				gItem.flashObj.delay(delayTime).fadeTo(80, 0.5, 'easeOutQuad', gItem.showImage).fadeOut(120, 'easeOutQuad');
			},
			showImage : function (){
				gItem.content.children('img').show();
				gItem.content.show();
				gItem.obj.hover(gItem.onMouseOver,gItem.onMouseOut);
				gItem.obj.addClass('loaded');
			}
		}
		gItem.init();
	
	});
	
};
