 $.fn.make_tabs = function(opts) { 
 $(".swap_tab").text('View as List').attr('title', 'View as List')
 if($(".swap_tab").hasClass('tab_view')){$(".swap_tab").removeClass('tab_view').addClass('list_view');}
 $(".tab_button").removeClass('list');
 $(".swap_tab").find('img').attr('alt', 'View as List').attr('title', 'View as List');
 $('.tabcontent_footer').remove();
 $(".tab_holder").append('<div class="tabcontent_footer"></div>');	

    var defaults = {  
		item_selector:'.info_item',
		link_selector:'.info_heading',
		content_selector:'.info_content',
		showing:''
    };   
    var o = $.extend(defaults, opts); 
	
    return this.each(function(idx) {
		var selfref=$(this).addClass('current_tab');
		
		var rebuild=false;
		if(selfref.data('tabs')){
			rebuild=true;
			selfref.data('tabs').displayHolder.show();
		}else{
			selfref.data('tabs',selfref)
			selfref.displayHolder = $('<div class="tab_display"></div>');
			$(o.item_selector+':first',selfref).addClass("first").after(selfref.displayHolder);
			if($(o.item_selector).length>1){
				$(o.item_selector+':last',selfref).addClass("last").after(selfref.displayHolder);
				$(o.item_selector,selfref).each(function(idx){
					var me=$(this)
					var myLevel = me.siblings().length - idx;
					me.css('z-index',myLevel);											 
				})
			}


			selfref.showItem = function (toShow) {
				if (selfref.hasClass("current_tab")) {
					$(o.item_selector, this).removeClass("tab_open").addClass("tab_closed");
					$(o.content_selector, this).css('display', 'none');
					$(toShow).addClass("tab_open").removeClass("tab_closed");
					if (o.showing.length > 0) {
						o.showing.append($(o.content_selector, this.displayHolder).hide());
					}
					this.displayHolder.append($(o.content_selector, toShow).show());
					o.showing = toShow;

				}
			} 
			selfref.restore = function(){   
			if(o.showing.length>0){
				o.showing.append($(o.content_selector,this.displayHolder).hide());
			}
			o.showing='';
			$(o.item_selector,selfref).each(function(i){
				var me	= $(this);
				$(o.link_selector, this).unbind("click",function(){selfref.showItem(me);return false;});
			;});
		 }
		 var tabend=$('<span class="tab_end"><img alt="" src="/images/spacer.gif"/></span>')
		var links=	$(o.link_selector +' h3',selfref).each(function(){
			var t=$(this);
			if(!(t.children('span:last-child').hasClass('tab_end'))){
				t.append(tabend);
			}
		});
		if(links.length>1){
			links.css('cursor','pointer');
		}
		}
		
		$(o.item_selector,selfref).each(function(i){
			var me	= $(this);
			$(o.link_selector, this).bind("click",function(){selfref.showItem(me);return false;});
		;});
		
		selfref.data('tabs').showItem($($(o.item_selector,selfref)[0]));
    }); 
	
 };   


$.fn.make_list = function(opts) { 
	$(".swap_tab").text('View as Tabs').attr('title', 'View as Tabs')
	$(".swap_tab").removeClass('list_view').addClass('tab_view');
	$(".tab_button").addClass('list');
	$('.tabcontent_footer').remove();
	$('.tab_holder').data('tabs').restore();
	$(".tab_block").append('<div class="tabcontent_footer"></div>');
	
	return this.each(function() {
		var me=$(this).removeClass('current_tab')
		$('.tab_end',me).remove();
		//$('.tab_display',me).remove();
		$('.tab_display',me).hide();
		$('.tab a',me).css({"textDecoration":"none"});
		$('.tabcontent',me).css({"display":"block"});
		//$('.tab_block',me).removeClass("last").removeClass("first").removeClass("tab_open").removeClass("tab_closed");
		$('.tab_block',me).removeClass("last").removeClass("tab_open").removeClass("tab_closed");
	 })
};


//JPLAYER
var playItem = -1;
var myPlayList = [];
	
function clearPlayList(){
	myPlayList = [];
	playItem = -1;
}

function showTrackImage(index){
	if(index > -1){
		var title = $("#album_title_" + index).val();
		var image = $("#album_image_" + index).val();
		
		$("#search_album_cover").html('<img title=\'' + title +  '\' alt=\'' + title + '\' src='+ image + " />" );
	}

}

function hideTrackImage(){
	$("#search_album_cover").html('');
}
	
function playListPlayTrack(index){
		if (playItem != index) {
					playListChange(index);
				} else {
					if($("#jquery_jplayer").length > 0){$("#jquery_jplayer").jPlayer("play");}
					showTrackImage(index);
				}
	}
	
	function playListInit(autoplay) {
		if(autoplay) {
			playListChange( playItem );
		} else {
			playListConfig( playItem);
		}
	}

	function playListConfig( index ) {

		if(index > -1){
		$("#jplayer_playlist_item_"+playItem).removeClass("jplayer_playlist_current").parent().removeClass("jplayer_playlist_current").before().parent().removeClass("jplayer_playlist_current");
		$("#jplayer_playlist_item_"+index).addClass("jplayer_playlist_current").parent().addClass("jplayer_playlist_current").before().parent().addClass("jplayer_playlist_current");

		playItem = index;
		$("#jquery_jplayer").jPlayer("setFile", myPlayList[playItem].mp3,'');
		$(".now_playing").html("Now Playing: <span class='jp-playlist' id='jplayer_song'>"+myPlayList[index].name+"</span>");
		showTrackImage(index);
		}
	}

	function playListChange( index ) 
	{
		$(".play_small_b").removeClass("play_small_b").addClass("play_small").text('Play');
		
		playListConfig( index );
		$("#jquery_jplayer").jPlayer("play");	
		$("#jplayer_playlist_item_"+index).removeClass("play_small").addClass("play_small_b").text('Playing');

		showTrackImage(index);
	}

	function playListNext() {
		var index = (playItem+1 < myPlayList.length) ? playItem+1 : 0;
		playListChange( index );
	}

	function playListPrev() {
		var index = (playItem-1 >= 0) ? playItem-1 : myPlayList.length-1;
		playListChange( index );
	}
	
	
	
	
function alsobought_scroller(){
 //Get our elements for faster access and set overlay width
 var div = $('div.sc_menu'),
 ul = $('ul.sc_menu'),
 // unordered list's left margin
 ulPadding = 15;
 //Get menu width
 var divWidth = div.width();

 //Remove scrollbars
 div.css({overflow: 'hidden'});

 //Find last image container
 var lastLi = ul.find('li:last-child');

 //When user move mouse over menu
 div.mousemove(function(e){

 //As images are loaded ul width increases,
 //so we recalculate it each time
 var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;

 var left = (e.pageX - div.offset().left) * (ulWidth-divWidth) / divWidth;
 div.scrollLeft(left);
 });
}; 
	
/* Stylish Select 0.3 - $ plugin to replace a select drop down box with a stylable unordered list
http://scottdarby.com/

Copyright (c) 2009 Scott Darby

Requires: $ 1.3

Licensed under the GPL license:
http://www.gnu.org/licenses/gpl.html
*/
(function($){
$('html').addClass('js');
Array.prototype.indexOf = function (obj, start) {
for (var i = (start || 0); i < this.length; i++) {
if (this[i] == obj) {
return i;
}
}
}
$.fn.extend({
getSetSSValue: function(v){ 
var el=this[0];
if (v){ 
return this.each(function(idx){
var i=0;
$('option',this).each(function(idx){if(this.value==v){i=idx}});
this.selectedIndex=i;
$(this).change();
})

} else {
return el.options[el.selectedIndex].value;
} 
},
resetSS: function(){
$this = $(this);
$this.next().remove();
$this.unbind().sSelect();
}
});

$.fn.sSelect = function(options) { 
return this.each(function(){ 
var defaults = {
defaultText: 'Please select',
animationSpeed: 0, 
ddMaxHeight: 245
};
var $input = $(this); 
if($input.hasClass('styled')){
	$input.unbind();
}
var opts = $.extend(defaults, options),
$containerDivText = $('<div class="selectedTxt"></div>'),
$containerDiv = $('<div class="newListSelected" tabindex="0"></div>'),
$newUl = $('<ul class="newList"></ul>'),
itemIndex = -1,
currentIndex = -1,
keepClass = '',
keys = [],
prevKey = false,
newListItems = '',
prevented = false;
$containerDiv.insertAfter($input);
$containerDivText.prependTo($containerDiv);
$newUl.appendTo($containerDiv);
$input.hide();
$input.addClass('styled');
if($input.attr('id')){$containerDiv.addClass($input.attr('id'));}
if ($input.children('optgroup').length == 0){
$input.children().each(function(i){
var option = $(this).text();
keys.push(option.charAt(0).toLowerCase());
if ($(this).attr('selected') == true){
opts.defaultText = option;
currentIndex = i;
}
var myClass = $(this).attr('class')
newListItems += '<li class="'+myClass+'">'+option+'</li>';
});
$newUl.html(newListItems);
newListItems = '';
var $newLi = $newUl.children();

} else { 
$input.children('optgroup').each(function(i){ 
var optionTitle = $(this).attr('label'),
$optGroup = $('<li class="newListOptionTitle">'+optionTitle+'</li>'); 
$optGroup.appendTo($newUl);
var $optGroupList = $('<ul></ul>');
$optGroupList.appendTo($optGroup);
$(this).children().each(function(){
++itemIndex;
var option = $(this).text();
//add first letter of each word to array
keys.push(option.charAt(0).toLowerCase());
if ($(this).attr('selected') == true){
opts.defaultText = option;
currentIndex = itemIndex;
}

var myClass = $(this).attr('class')
newListItems += '<li class="'+myClass+'">'+option+'</li>';
})
$optGroupList.html(newListItems);
newListItems = '';
});
var $newLi = $newUl.find('ul li'); 
}
var newUlHeight = $newUl.height()+3,
containerHeight = $containerDiv.height(),
newLiLength = $newLi.length;

if (newUlHeight == 3){
var selectWidth = $newUl.width();
var dummy = $('<div style="position:absolute; width: '+selectWidth+'"/>')
dummy.append($newUl.clone())
$('body').append(dummy);
newUlHeight += $('ul', dummy).height(); 
dummy.remove();
}

if (currentIndex != -1){ 
navigateList(currentIndex, true);
} else {
$containerDivText.text(opts.defaultText);
}
function newUlPos(){
var containerPosY = $containerDiv.offset().top,
docHeight = jQuery(window).height(),
scrollTop = jQuery(window).scrollTop();
if (newUlHeight > parseInt(opts.ddMaxHeight)) {
newUlHeight = parseInt(opts.ddMaxHeight);
$newUl.addClass('tooHigh')
}
containerPosY = containerPosY-scrollTop;
if (containerPosY+newUlHeight >= docHeight){
$newUl.css({top: '-'+newUlHeight+'px'/*, height: newUlHeight*/});
$input.onTop = true;
} else {
$newUl.css({top: containerHeight+'px'/*, height: newUlHeight*/});
$input.onTop = false;
}
}
newUlPos();
$(window).resize(function(){
newUlPos();
}); 
$(window).scroll(function(){
newUlPos();
});
function positionFix(){
$containerDiv.css('position','relative');


}
function positionHideFix(){
$containerDiv.css('position','relative');
}
$containerDivText.click(function(){ 
if ($newUl.is(':visible')){
$newUl.hide();
positionHideFix()
return false;
}
$containerDiv.focus();
$newUl.slideDown(opts.animationSpeed);
positionFix();
$newUl.scrollTop($input.liOffsetTop);
}); 
$newLi.hover(
function (e) {
var $hoveredLi = $(e.target);
$hoveredLi.addClass('newListHover');
},
function (e) {
var $hoveredLi = $(e.target);
$hoveredLi.removeClass('newListHover');
}
);
$newLi.click(function(e){
var $clickedLi = $(e.target);

opts.keepClass = 'same_day';
if($clickedLi.is('.next_day')){
	opts.keepClass = 'next_day';
}

currentIndex = $newLi.index($clickedLi);
prevented = true;
navigateList(currentIndex);
prevented = false;
$newUl.hide();
$containerDiv.css('position','static');//ie
});
function navigateList(currentIndex, init){
var containerOffsetTop = $containerDiv.offset().top,
liOffsetTop = $newLi.eq(currentIndex).offset().top,
ulScrollTop = $newUl.scrollTop(); 
if ($input.onTop == true){
$input.liOffsetTop = (((liOffsetTop-containerOffsetTop)-containerHeight)+ulScrollTop)+parseInt

(opts.ddMaxHeight);
} else {
$input.liOffsetTop = ((liOffsetTop-containerOffsetTop)-containerHeight)+ulScrollTop;
} 
$newUl.scrollTop($input.liOffsetTop);
$newLi.removeClass('hiLite')
.eq(currentIndex)
.addClass('hiLite');
var text = $newLi.eq(currentIndex).text();

if (init == true){ 
$containerDivText.text(text)
return false;
}
$input[0].selectedIndex=currentIndex;
if(opts.changeSiblings){ 
$input.siblings('select').getSetSSValue($input.val());

} 
$containerDivText.removeClass('same_day next_day')
$containerDivText.text(text).addClass(opts.keepClass);
//if(opts.setSize){
//setSizeID($input[0]);
//}
$input.trigger('change');
};

$input.bind('change',function(event){
$targetInput = $(event.target); 
if (prevented == true){
prevented = false;
return false;
}
$currentOpt = $targetInput.find(':selected');
currentIndex = $targetInput.find('option').index($currentOpt);
navigateList(currentIndex, true);

}
);
function keyPress(element) {
element.onkeydown = function(e){
if (e == null) { 
var keycode = event.keyCode;
} else { 
var keycode = e.which;
} 
prevented = true;
switch(keycode)
{
case 40: //down
case 39: //right
incrementList();
prevented = false;
return false;
break;
case 38: //up
case 37: //left
decrementList();
prevented = false;
return false;
break;
case 33: //page up
case 36: //home
gotoFirst();
prevented = false;
return false;
break;
case 34: //page down
case 35: //end
gotoLast();
prevented = false;
return false;
break;
case 13:
case 27:
$newUl.hide();
positionHideFix();
prevented = false;
return false;
break;
}
keyPressed = String.fromCharCode(keycode).toLowerCase();
var currentKeyIndex = keys.indexOf(keyPressed);
if (typeof currentKeyIndex != 'undefined') { 
++currentIndex;
currentIndex = keys.indexOf(keyPressed, currentIndex); 
if (currentIndex == -1 || currentIndex == null || prevKey != keyPressed) currentIndex =

keys.indexOf(keyPressed); 
navigateList(currentIndex);
prevKey = keyPressed;
prevented = false;
return false;
}
prevented = false;
}
}
function incrementList(){
if (currentIndex < (newLiLength-1)) {
++currentIndex;
navigateList(currentIndex);
}
}
function decrementList(){
if (currentIndex > 0) {
--currentIndex;
navigateList(currentIndex);
}
}
function gotoFirst(){
currentIndex = 0;
navigateList(currentIndex);
}
function gotoLast(){
currentIndex = newLiLength-1;
navigateList(currentIndex);
}
$containerDiv.click(function(){

keyPress(this);
});
$containerDiv.focus(function(){
$(this).addClass('newListSelFocus');
keyPress(this);
}); 
$containerDiv.blur(function(){
$(this).removeClass('newListSelFocus');
$newUl.hide();
positionHideFix();
}); 
$containerDivText.hover(function(e) {
var $hoveredTxt = $(e.target);
$hoveredTxt.parent().addClass('newListSelHover');
}, 
function(e) {
var $hoveredTxt = $(e.target);
$hoveredTxt.parent().removeClass('newListSelHover');
}
); 
$newUl.css('left','0').hide();
}); 
};
})(jQuery);
	
	
	
	
	
(function ($) {
    $.fn.vAlign = function(container) {
        return this.each(function(i){
	   if(container == null) {
	      container = 'div';
	   }
	   var paddingPx = 10; //change this value as you need (It is the extra height for the parent element)
	   $(this).html("<" + container + ">" + $(this).html() + "</" + container + ">");
	   var el = $(this).children(container + ":first");
	   var elh = $(el).height(); //new element height
	   var ph = $(this).height(); //parent height
	   if(elh > ph) { //if new element height is larger apply this to parent
	       $(this).height(elh + paddingPx);
	       ph = elh + paddingPx;
	   }
	   var nh = (ph - elh) / 2; //new margin to apply
	   $(el).css('margin-top', nh);
        });
     };
})(jQuery);	
	
	
	
	
	
$(document).ready(function(){	

$('.result_container .result_img').vAlign()

$('.newListSelected').remove();
$('.check_instore_details select, .delivery_address_details select, .your_address_options select, #cart table.summary .delivery select').sSelect();

//jplayer
if($("#jquery_jplayer").length > 0){
	var jpPlayTime = $("#jplayer_play_time");
	var jpTotalTime = $("#jplayer_total_time");
    $("#jquery_jplayer").jPlayer({
		ready: function() {
			playListInit(false); // Parameter is a boolean for autoplay.
		},
		swfPath: "/scripts/jplayer/",
		oggSupport: false
	})
	
	.jPlayer("onProgressChange", function(loadPercent, playedPercentRelative, playedPercentAbsolute, playedTime, totalTime) {
		jpPlayTime.html($.jPlayer.convertTime(playedTime*1000));
		jpTotalTime.html($.jPlayer.convertTime(totalTime));
	})
	
	.jPlayer("onSoundComplete", function() {
		playListNext();
	});

	$("#jplayer_previous").click( function() {
		playListPrev();
		$(this).blur();
		return false;
	});

	$("#jplayer_next").click( function() {
		playListNext();
		$(this).blur();
		return false;
	});


	$("#jplayer_stop").click( function() {
		hideTrackImage();
		$(this).blur();
		return false;
	});
	
	$('#sliderVolume').slider({
		value: 50,
		max: 100,
		range: 'min',
		animate: true,

		change: function (event, ui) { $("#jquery_jplayer").jPlayer("volume", ui.value); }
	});

	$("#speaker").toggle(
		function () { $('#speaker').css("background-image", "url(/../images/digi_downloads/mute.png)"); $('#sliderVolume').slider("value", 0) },
		function () { $('#speaker').css("background-image", "url(/../images/digi_downloads/player-speaker.png)"); $('#sliderVolume').slider("value", 50) }
	);

}
//jplayer end	
	
	$('.item_container_hide').hide();
	
	$('.tab_holder').make_tabs({item_selector:'.tab_block', link_selector:'.tab',content_selector:'.tabcontent'});  

	
	$(".swap_tab").toggle(					  
		function (){$('.tab_holder').make_list(); },
		function (){$('.tab_holder').make_tabs({item_selector:'.tab_block', link_selector:'.tab',content_selector:'.tabcontent'}); }	
	);
	

	
	alsobought_scroller();
	

	
});

