
	var site = {
		imageRotator: function() {
			$('div#rotator ul li').css({opacity: 0.0});
			$('div#rotator ul li:first').css({opacity: 1.0});
			setInterval('site.rotate()',4000);
		  
		},

		rotate: function() {	
				var current = ($('div#rotator ul li.show')?  $('div#rotator ul li.show') : $('div#rotator ul li:first'));
				var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#rotator ul li:first') :current.next()) : $('div#rotator ul li:first'));	
				
				//Set the fade in effect for the next image, the show class has higher z-index
				next.css({opacity: 0.0})
				.addClass('show')
				.animate({opacity: 1.0}, 1000);
			
				//Hide the current image
				current.animate({opacity: 0.0}, 1000)
				.removeClass('show');	
		},
		
	    randomNumber: function(numItems, startNumber, cookieName) {
			var result
			var numItemsPlusCommas = parseInt(numItems * 2 ) + 1 
			
			if($.cookie(cookieName) == null) {
				if(startNumber != '') {
					result = startNumber
					$.cookie(cookieName, ',' + startNumber + ',');	
				} else {
					$.cookie(cookieName, ',');	
				}
			} else {
				if($.cookie(cookieName).length == numItemsPlusCommas) {
					$.cookie(cookieName, ',');	 // start over
				}
	
				var gotNumber		
				// check to see of item has been viewed	
				// if not choose unused number
				do {
				var result = Math.floor(Math.random() * numItems);
				result = result + 1	
				if ($.cookie(cookieName).indexOf(',' + result + ',') != -1){
					gotNumber = 'false'	
				} else {	
					$.cookie(cookieName, $.cookie(cookieName) +  result + ',');
					gotNumber = 'true'
				}
				}
				while (gotNumber == 'false');
			}
			return result;		
		}
		
	}
	
	site.headphones = {
		hideBannerCarouselInfo: function () {
			$('.headphone-img').removeClass('headphone-img-off-main').removeClass('headphone-img-on');	
			$('#carousel-wrapper').css('background-color' , '#fff');			
			$('.bannerinfo').hide();
			$('.carouselinfo').hide();			
		},
		
		nextPrev: function () {
			$('.headphone-img').removeClass('headphone-img-off-main').removeClass('headphone-img-on');				
			site.headphones.hideBannerCarouselInfo();
		},
		
		itemHoverOn: function (o) {
			site.headphones.hideBannerCarouselInfo();

			var img = $(o).attr('id');
			var bannerinfo = img.replace('headphone', 'bannerinfo');
			var carouselinfo = img.replace('headphone', 'carouselinfo');
			
			$('.headphone-img').addClass('headphone-img-off-main');
			$(o).removeClass('headphone-img-off-main');
			$(o).addClass('headphone-img-on');
			$('#carousel-wrapper').css('background-color' , '#3a3a3a');
			$('#' + bannerinfo).fadeIn('slow');
			$('#' + carouselinfo).show('fast');
			 
		},
		
		itemHoverOff: function (o) {
			$('.headphone-img').removeClass('headphone-img-off-main').removeClass('headphone-img-on-main');				
			site.headphones.hideBannerSliderInfo();	 
			$('#carousel-wrapper').css('background-color' , '#fff');
		},
		
		bannerInfoOn: function (o) {
			$('.headphone-img').removeClass('headphone-img-off-main').removeClass('headphone-img-on');				
			site.headphones.hideBannerCarouselInfo;			
		},
		
		findIds: function (o) {
			var img = $(o).attr('id');
			var bannerinfo = img.replace('headphone', 'bannerinfo');
			var carouselinfo = img.replace('headphone', 'carouselinfo');			
		},
		animateOver: function(o) {
			
			// link 
			var linkTemp = $(o).attr('ref');
			$('#thumb-on').attr('ref', linkTemp);

			// set up
			var navMoveDistance = '15px';
			var onTop = -23
			var onLeft = -8;
	
			// durations
			var navDuration = 100; //time in miliseconds
	
			var thumbId = $(o).attr('id');
			var featureCopy = thumbId.replace('thumb', 'copy');
			var featureImg = 'images/featured/artist-bgg' + thumbId.replace('thumb', '') + '.jpg';
			
			$('#feature-img').hide();	
			$('#feature-img').attr('src', featureImg).css('z-index', '-1');
			$('#feature-img').fadeIn('slow');
		
			var position = $(o).position();
			
			onTop = onTop;
			onLeft = position.left + onLeft;
			
			$(o).css('z-index', '100');	
			$('#thumb-on').show();	
			$('#thumb-on').css({'top' : onTop, 'left' : onLeft, 'z-index' : '999'});
			
			$('#' + featureCopy).show();
			
          	$(o).stop().animate({ 
			  top : '-='+navMoveDistance},  
			  navDuration,
			  	function () {
			  	//$(o).show("puff", { percent: 105 }, 300);
			  	//$(o).show("puff", { percent: 100 }, 300, "easeOutElastic");

			  }			
			);
		},
		
		animateOff: function(o) {
			// set up
			var navMoveDistance = '-15px';
			
			// durations
			var navDuration = 150; //time in miliseconds

			var thumbIdOff = $(o).attr('id');
			var featureCopy = thumbIdOff.replace('thumb', 'copy');
			
			$(o).css('z-index', '');		
			
			$('#thumb-on').hide();
			$('#thumb-on').css({'top' : '', 'left' : '', 'z-index' : ''});
						
          	$(o).stop().animate({ top : '-='+navMoveDistance }, navDuration);
			$('#' + featureCopy).hide('fast');	

		},
		
		resetThumbs: function(o) {
				$('.thumb').each(function(index, value){
					var position = $(this).position();
					  if (position.top < -14) {
						  site.headphones.animateOff(this);
					  }
				});			
		},
		
		spotlightVideo: function() {
	
			var spotlightFrame
			spotlightFrame = $('#monstervideos-spotlight');
			
			switch (site.randomNumber('4','1','spotlightvideo')) {
			case 1:
				$(spotlightFrame).attr('src','videoplayer.asp?size=spotlight&id=32');
				$('#spotlight-video01').show();
				$('#overlay01').delay(900).fadeIn();
			  break;
			case 2:
				$(spotlightFrame).attr('src','videoplayer.asp?size=spotlight&id=33');
				$('#spotlight-video02').show();
				$('#overlay02').delay(900).fadeIn();
			  break;
			case 3:
				$(spotlightFrame).attr('src','videoplayer.asp?size=spotlightsm&id=34');
				$('#spotlight-video03').show();
				$('#overlay03').delay(900).fadeIn();
				$('iframe').attr('height','275');
				$('iframe').attr('width','490');
			  break;
			case 4:
				$(spotlightFrame).attr('src','videoplayer.asp?size=spotlight&id=35');
				$('#spotlight-video04').show();
				$('#overlay04').delay(900).fadeIn();
			  break;
			default:
				$(spotlightFrame).attr('src','videoplayer.asp?size=spotlight&id=32');
				$('#spotlight-video01').show();
				$('#overlay01').delay(900).fadeIn();
			}			
		}
	}
	

	$(document).ready(function(){
		
		// for mobile videos
		browser = GetBrowser(navigator.userAgent.toLowerCase());
		if (browser.indexOf("Mobile") >= 0){
			var videolink
			$('.video-link-image,.video-link').each(function(index, value){
				videolink = $(this).attr('href');
				if (videolink != undefined) {
					if (videolink.indexOf('videoplayer.asp') != -1) {
						$(this).attr('href', $(this).attr('name'));
						$(this).attr('rel', '');
					}
				}
			});		
		}
		
	
		site.headphones.spotlightVideo();		
		site.imageRotator();
		
		$('#carousel-wrapper').show("drop", {direction: "right"}, 800,
		  function () {
			  $(this).css('opacity', '1.0');
			  $(this).effect("bounce", { times:5 , direction: 'right', distance: 12}, 200);
			  }			
		);

		var slider = $('.carousel').bxSlider({
		randomStart: false,
		nextType: 'image',
		nextImage: '/js/bxSlider/bx_styles/monster-next.png',
		prevType: 'image',
		prevImage: '/js/bxSlider/bx_styles/monster-prev.png',	
		auto: false,
		displaySlideQty: 5,
		moveSlideQty: 4,
		randomStart: false,
		autoStart: false,
		pause: 1400,
		speed: 500,
		controls: true,
		infiniteLoop: true,
		onPrevSlide: function(currentSlide){
		slider.goToNextSlide();
		slider.autoDirection = 'next';
		slider.startShow();
		},
		onNextSlide: function(currentSlide){
		slider.goToPreviousSlide();
		slider.autoDirection = 'prev';
		slider.startShow();
		}
		});
		
		var videos = $('.videos').bxSlider({
		nextClass: 'video-next',
		nextType: 'image',
		nextImage: '/js/bxSlider/bx_styles/arrow-next.png',
		prevClass: 'video-prev',
		prevType: 'image',
		prevImage: '/js/bxSlider/bx_styles/arrow-prev.png',
		auto: false,
		displaySlideQty: 3,
		moveSlideQty: 1,
		randomStart: false,
		autoStart: false,
		pause: 1400,
		speed: 500,
		controls: true,
		infiniteLoop: true,
		onPrevSlide: function(currentSlide){
		videos.goToNextSlide();
		videos.autoDirection = 'next';
		videos.startShow();
		},
		onNextSlide: function(currentSlide){
		videos.goToPreviousSlide();
		videos.autoDirection = 'prev';
		videos.startShow();
		}
		});
		
		$('.bx-prev,.bx-next').mouseover(function () {
				site.headphones.hideBannerCarouselInfo();
				$('#rotator').show();			
				slider.startShow();
		});
		
		$('.headphone-img').hover(
			function () {         // stop show and show divs
				slider.stopShow();
				$('#rotator').hide();	
				site.headphones.itemHoverOn(this);
			},
			function () {		// start show and hid divs			
				var img = $(this).attr('id');
				var bannerinfo = img.replace('headphone', 'bannerinfo');
				var carouselinfo = img.replace('headphone', 'sliderinfo');
				$('#rotator').show();		
				}
		);
		
		$('.carouselinfo').hover(
			function () {
				slider.stopShow();	
			},
			function () {		
				site.headphones.hideBannerCarouselInfo();
				$('#rotator').show();			
				slider.startShow();
			}
		);	
		
		$('.bannerinfo').mouseover(
			function () {		
				site.headphones.hideBannerCarouselInfo();
				$('#rotator').show();	
				slider.startShow();
								
			}
		);	
		
		// random set of thumbs
		var randomThumbs = Math.floor(Math.random()*2);
		var arrayThumbs

		if (randomThumbs == '0') {
			$('#thumb-06,#thumb-07').hide();
			$('#thumb-06,#thumb-05').show();
			arrayThumbs = [1,2,3,6,5];
		} else {
			$('#thumb-04,#thumb-05').hide();
			$('#thumb-06,#thumb-07').show();
			arrayThumbs = [1,2,3,6,7];
		}
		
		arrayThumbs = [1,2,3,6,7];
		
		var randomNumber = Math.floor(Math.random() * 5);
		var randomStart = '#thumb-0' + arrayThumbs[randomNumber];

		if($(randomStart).length != 0){ //test that the element exists
			site.headphones.animateOver(randomStart);
		} else {
			$('#feature-img').attr('src', 'images/feature-holder.jpg');
	
		}
		
		// featured artists	
		function thumbOver () {
			//alert('got here');
			site.headphones.resetThumbs(this);
			var position = $(this).position();
			if (position.top == 0) {
			   site.headphones.animateOver(this);	
			}			
		}
		
		function thumbOff() {}
		
		var configThumbs = {    
			 over: thumbOver,   
			 timeout: 200, 
			 out: thumbOff,
			 interval: 200
		};
		
		$('.thumb').hoverIntent(configThumbs);
		
		$('#thumb-on').click(function() {
			var linkurl = $(this).attr('ref');
			//console.log(linkurl);
			if (linkurl != 'undefined') {
			window.location = $(this).attr('ref');
			}
			
		});
		

		
	});	
