$(document).ready(function(){
		//Sub navigation Switch
		$("#landing a").hover(
		function () {
		$(this).addClass("hover");
		},
		function () {
		$(this).removeClass("hover");
		}
		);

		//errMsg
		$("div#errors > div").delay(5000).fadeOut("slow").slideUp("slow")

		///Splash and Frontpage Slideshow
		$("#featured > ul").tabs({fx:{opacity: "toggle"}}).tabs("rotate", 7000, true);
		
		///Gallery Slideshow
		$('#mycarousel').jcarousel({wrap: 'circular' });
		
		///Most Popular Carousel
		$('#mostpopular').jcarousel({
		wrap: 'circular',
		slideEasing: "easeOutBounce",
		dispItems: 1
		});
		
		///Tab Box Tabs
		$(".tab_content").hide(); //Hide all content
		$("ul.tabs li:first").addClass("active").show(); //Activate first tab
		$(".tab_content:first").show(); //Show first tab content
		
		//On Click Event
		$("ul.tabs").tabs("select","tab2");
		$("ul.tabs li").click(function() {
		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content
		var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active content
		return false;
		});
		
		///FancyBox
		$("a#single_image").fancybox({'overlayColor':'#000000','overlayOpacity':0.6,'transitionIn':'fade','transitionOut':'fade','speedIn':600,'speedOut'		:600});
		
		$("a.group").fancybox({'overlayColor':'#000000','overlayOpacity': 0.6,'transitionIn':'fade','transitionOut':'fade','speedIn':600,'speedOut':600});
		
		$("a#button_image").fancybox({
		'overlayColor': '#000000',
		'overlayOpacity': 0.6,
		'transitionIn'	:	'fade',
		'transitionOut'	:	'fade',
		'speedIn'		:	600, 
		'speedOut'		:	600});
		
		$("#reviewForm").fancybox({
		'overlayColor': '#000000',
		'overlayOpacity': 0.6,
		'titlePosition'		: 'inside',
		'transitionIn'		: 'fade',
		'transitionOut'		: 'fade',
		'speedIn'		:	600, 
		'speedOut'		:	600
		});
		
		//Star Rating
		$(".star_rating").stars();

		//Thumbnails
		$(".latest_img").fadeTo("slow", 1.0); 
						   $(".latest_img").hover(function(){
						   $(this).stop().fadeTo("slow", 0.7); 
						   },function(){
						   $(this).stop().fadeTo("slow", 1.0); 
						   });
		//Product Thumbnail Switch
		  $(".other-thumbnails a").hover(
		  function () {
		  var largePath = $(this).attr("ret");
			$("#largeImage").attr({ src: largePath });

		  return false;
		  },
		  function () {
		  var largePath = $(this).attr("ret");
		  var ltBoxPath = $(this).attr("href");
		  
		  //update links to new image path
		  $("a.main").attr({ href: ltBoxPath });
		  $("#largeImage").attr({ src: largePath });
		  return false;
		  });


		//Sub navigation Switch
		$("#sub-nav li a").hover(
		function () {
		$(this).addClass("hover");
		},
		function () {
		$(this).removeClass("hover");
		}
		);

		//Content Column Height
		var contentHeight = $(".grid-7").height();	
		var altHeight = $(".grid-10").height();	
		
		if (contentHeight < 630)
		{
		$('.padded-base').css('height', 630);
		}
	
		//Duplicate pagination
		var pageLinks = $(".pageLinks").html();
		$(".top-links").append(pageLinks)
		
		
		//share this links
		//var iUrl = $(".title").find(".iurl").val()
		//var iTitle = $(".title").find(".ititle").val()
		//var iDesc = $(".title").find("idesc").val()
		
		$('.share').share({
		//url:		iUrl,
		//title:		iTitle,
		//description: iDesc,
		services:		['email', 'facebook', 'twitter', 'myspace', 'google', 'stumbleupon' , 'yahoo', 'delicious'],
		img_size:		24,
		a_target:		'_Blank'
		});
		
		//search form change
		$("#searchsite").change(function() {
 		 var action = $(this).val();
		 //alert(action);
  		$("#searchform").attr("action", "/"+ action + "/search/default.asp" );
		});
		
		//hear the call player
		$('#mad_player').jPlayer({
		swfPath: '/javascript',
		solution: 'html, flash',
		supplied: 'mp3',
		volume: 0.8,
		muted: false,
		cssSelectorAncestor: '#sound-selector',
		cssSelector: {
		play: '.play',
		pause: '.pause',
		stop: '.stop',
		seekBar: '.seek-bar',
		playBar: '.play-bar',
		mute: '.mute',
		unmute: '.unmute',
		volumeBar: '.volume-bar',
		volumeBarValue: '.volume-bar-value',
		currentTime: '.current-time',
		duration: '.duration'
		},
		ready: function () {
		
		//when ready load sound clip and poster
     	var intSrc = $("#playlist li a:first").attr('alt');
		var intSoundClip = $("#playlist li a:first").find('span').html();
		var intId = $("#playlist li a:first").find('span').html();
		
		$('#mad_player').jPlayer("setMedia", { mp3: "/sound/mp3/"+ intSoundClip +".mp3" });
		$('#slide').html('<a href="/mad/default.asp?p=Details&i='+ intId +'"><img src="'+ intSrc +'" width="527" height="150" border="0" /></a>');
    	
		},
		errorAlerts: false,
		warningAlerts: false
		});
		
		//Clip function for playlist
		$("#playlist a").click(function(){
		
		//Define vars
		var itemID = $(this).attr('id');
		var src = $(this).attr('alt');
		var soundClip = $(this).find('span').html();
		
		$('#mad_player').jPlayer("setMedia", { mp3: "/sound/mp3/"+ soundClip +".mp3"}).jPlayer("play");
		
		//Hide and Change
		$('#playlist a').removeClass('active')
		$(this).addClass('active')
		$('#slide').hide();
		$('#slide').html('<a href="/mad/default.asp?p=Details&i='+ soundClip +'"><img src="'+ src +'" width="527" height="150" border="0" /></a>');
		$('#slide').fadeIn('slow');
		
		preventDefault();
		});
		
		///mad video player
		var intPoster = $("#video-playlist a:first").attr('alt');
		var intVideoClip = $("#video-playlist a:first").find('span').html();
		
		
		
		
		$('#mad-video').jPlayer({
		swfPath: '/javascript',
		solution: 'html, flash',
		supplied: 'ogv, m4v',
		preload: 'metadata',
		volume: 0.8,
		backgroundColor: '#000000',
		muted: false,
		cssSelectorAncestor: '#video-selector',
		cssSelector: {
		videoPlay: '.jp-video-play',
		play: '.vid-play',
		pause: '.vid-pause',
		stop: '.vid-stop',
		seekBar: '.seek-bar',
		playBar: '.play-bar',
		mute: '.vid-mute',
		unmute: '.vid-unmute',
		volumeBar: '.vid-volume-bar',
		volumeBarValue: '.vid-volume-bar-value',
		currentTime: '.vid-current-time',
		duration: '.vid-duration'
		},
		ready: function () {
			$(this).jPlayer("setMedia", {
				m4v: "/video/m4v/"+ intVideoClip +".m4v",
				ogv: "/video/ogv/"+ intVideoClip +".ogv",
				poster: "/video/posters/"+ intPoster 
			});
		},
		ended: function (event) {
			$('.jp-video-play').show();
			
			$(this).jPlayer("setMedia", {
				m4v: "/video/m4v/"+ lastPlayClip +".m4v",
				ogv: "/video/ogv/"+ lastPlayClip +".ogv",
				poster: "/video/posters/"+ lastPlayPoster
			});
		},
		play: function (event) {
			$('.jp-video-play').hide();
		},
		pause: function (event) {
			$('.jp-video-play').show();
		},
		errorAlerts: false,
		warningAlerts: false
		});

		$("#video-playlist a").hover(function() {
		  $(".hover-play").css('visibility' , 'hidden');
			}, function() {
		  $(".hover-play").css('visibility' , 'visible');
		});

		
		$("#video-playlist a").click(function(){
		
		//Define vars
		var poster = $(this).attr('alt');
		var videoClip = $(this).find('span').html();
		
		$('.jp-video-play').hide();
		
		$('#mad-video').jPlayer("setMedia", { 
		m4v: "/video/m4v/"+ videoClip +".m4v",
		ogv: "/video/ogv/"+ videoClip +".ogv",
		poster: "/video/posters/"+ poster
		}).jPlayer("play");
		
		//Hide and Change
		$('#video-playlist a').removeClass('video-active');
		$(this).addClass('video-active');
		preventDefault();
		});
		
		///prostaff carousel and photo slider//////////////////////
		//initial page content
		var content = $("#pro-staff-carousel li:first").find("#bio").html()
		$("#staff-content").append(content)
		
		//jCarousel Plugin
		$('#carousel').jcarousel({
		vertical: true,
		scroll: 1,
		auto: 2,
		wrap: 'circular',
		initCallback: mycarousel_initCallback,
		itemFirstInCallback: {onAfterAnimation: change_img}
		});
		
		
		//Combine jCarousel with Image Display
		$('div#pro-staff-carousel li a').hover(
		function () {
		
		if (!$(this).has('span').length) {
		$('div#pro-staff-carousel li a img').stop(true, true);
		$(this).stop(true, true).children('img');
		}		
		},
		function () {
		
		$('div#pro-staff-carousel li a img').stop(true, true);
		$('div#pro-staff-carousel li a').each(function () {
		
		if ($(this).has('span').length) $(this).children('img');
		
		});
		
		}
		).click(function () {
		var rel = "li#" + $(this).attr('rel');
		
		//empty page contents
		$("#staff-content").empty();
		
		
		//html content to fill page
		var bio = $(rel).find('div#bio').html();
		
		//fill page with new content
		$("#staff-content").append(bio);
		$("<div style='clear:both;'></div>").appendTo("#staff-content");
		
		//active class to main
		$('div#pro-staff-carousel li').removeClass('highlight');
		$('div#pro-staff-carousel li#' + $(this).attr('rel')).addClass('highlight');
		
		$('div#pro-staff-main li').removeClass('active');        
		$('div#pro-staff-main li.' + $(this).attr('rel')).addClass('active');	
		
		return false;
		});
		///////////////////////////////
		initMenu0();
		initMenu1();
		initMenu2();

//end document.ready
});

////Accordian Menu 0
		function initMenu0() {
		$('.main-0 ul').hide();
		$('.main-0 ul:first').show();
		$('.main-0 li a').click(
		function() {
		var checkElement = $(this).next();
		if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
		//return false;
		}
		if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
		$('.main-0 ul:visible').slideUp('normal');
		checkElement.slideDown('normal');
		return false;
		}
		}
		);
		}

////Accordian Menu 1
		function initMenu1() {
		$('.main-1 ul').hide();
		$('.main-1 ul:first').show();
		$('.main-1 li a').click(
		function() {
		var checkElement = $(this).next();
		if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
		//return false;
		}
		if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
		$('.main-1 ul:visible').slideUp('normal');
		checkElement.slideDown('normal');
		return false;
		}
		}
		);
		}
////Accordian Menu 1
		function initMenu2() {
		$('.main-2 ul').hide();
		$('.main-2 ul:first').show();
		$('.main-2 li a').click(
		function() {
		var checkElement = $(this).next();
		if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
		//return false;
		}
		if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
		$('.main-2 ul:visible').slideUp('normal');
		checkElement.slideDown('normal');
		return false;
		}
		}
		);
		}


//Carousel Tweaking
function mycarousel_initCallback(carousel) {
	
	// Pause autoscrolling if the user moves with the cursor over the clip.
	carousel.clip.hover(function() {
		carousel.stopAuto();
	}, function() {
		carousel.startAuto();
	});
}

function change_img(carousel, li, index, state)
{
var rel = $(li).contents('a');
$('div#pro-staff-main li').removeClass('active');
$('div#pro-staff-carousel li').removeClass('highlight');
$('div#pro-staff-main li.' + $(rel).attr('rel')).addClass('active');
$('div#pro-staff-carousel li#' + $(rel).attr('rel')).addClass('highlight');
}
