/* CRISS ANGEL */
/* Home Page Javascript
----------------------------------------------------------------------------- */


/* READY FUNCTION
----------------------------------------------------------------------------- */


	$(document).ready(function(){});


/* LOAD FUNCTION
----------------------------------------------------------------------------- */


	$(window).load(function() {
	

/* STORE FUNCTIONALITY
----------------------------------------------------------------------------- */

		if (section == "store") {
		
		
			// SUB-DEPARTMENTS
			$('#subcategories').each(function() {
		
				var category = $('#subcategories h3').text();
				$('#subcategories ul').find('a:contains("Everything")').parent().remove();
				$('#subcategories ul').appendTo('#departments li:has(a:contains("' + category + '"))');
				$('#subcategories').remove();
		
			});
			
			// PLUGIN: CLIQUE FORMS
			try {
			$('.widget-item.search input#query').cliqueForms({ placeholder: "Search Store" });
			$('.widget-item.search input#query').css('visibility', 'visible'); // Will not chain to previous function?
			$('#mailing_list_entry_email').cliqueForms({ placeholder: "Enter Your Email Address" });
			$('#mailing_list_entry_mobile').cliqueForms({ placeholder: "Enter Your Mobile Number" });
			} catch (error) { alert('Error: Missing Clique Forms Plugin'); }

			// PLUGIN: CLIQUE ITEM WIDGET
			try {
			$('div.widget-item.display:not(.photos, .gift)').cliqueItemWidget({

				checkStock: true,
				pressure: true,
				browser: 'thumbnails', // thumbnails / slideshow
				removeEmptyThumbs: true, // Removes rows of empty thumbnails
				viewer: true, // Shows enlarged images
				preview: false, // Preview enlarged images when hovering thumbnails
				zoom: 'drag' // loupe / drag / none

			});
			$('.widget-item.browse.tooltip').cliqueItemWidget();
			$('.widget-item.filter').cliqueItemWidget();
			} catch (error) { alert('Error: Missing Clique Item Plugin'); }

			// PLUGIN: CLIQUE ALERT WIDGET
			try { $('div.widget-alert.added').cliqueAlertWidget(); } catch (error) { alert('Error: Missing Clique Alert Plugin'); }

			// PLUGIN: CLIQUE UPLOADER
			if (page == "item" && $('#review').length > 0) { try { $('#review').cliquePhotoUploader(); } catch (error) { alert('Error: Missing Clique Uploader Plugin'); } }
			
			// PLUGIN: CLIQUE ACTIONS (Replaces submit buttons with text links)
			try { $('input[type=submit]').cliqueActions(); } catch (error) { alert('Error: Missing Clique Actions Plugin'); }
			
			// MAILING LIST
			$('#optin ul.actions li input.save').attr('value','Get Updates');
			$('#optin ul.actions li a.submit').text('Get Updates');
			
			// CART
			$('div#cart span:contains("You have")').remove();
			
		}
		

		
/* FLASH: HEADER
----------------------------------------------------------------------------- */
		
		var so = new SWFObject(asset_host + "/flash/preloadNH.swf", "nheader", "100%", "187", "8", "#000000");
		so.addParam( "allowScriptAccess", "always" );
		so.addVariable("netPath", site_host);
		so.addVariable("path", asset_host + "/flash/store_header.swf");
		so.write("header");
	
			
/* HIDDEN AUDIO PLAYER
----------------------------------------------------------------------------- */

		var myAudio = new mediaObject(asset_host + "/flash/audio_player.swf", "520", "467", "#000000", 'hidden','true'); 
		myAudio.setFeeds(site_host + "/playlists/audio.xml");

	
/* POPUP EXTERNAL LINKS
----------------------------------------------------------------------------- */


		$('a[rel=external]').click(function(){
		
			link = $(this).attr('href');
			window.open(link);
			return false;
	
		});
	

/* STORE FUNCTIONS
----------------------------------------------------------------------------- */

		cufon();
		tabs();
		killTabs();
		
	});
	
	
/* FUNCTION: CUFON
----------------------------------------------------------------------------- */

	function cufon() {

		// DIN
		Cufon.replace('div#cart h3, div.widget-alert h3', { fontFamily: 'DIN' }, { textShadow: '#000 1px 1px' });
				
		// Garaline
		Cufon.replace('h3.shop, #title h2, div.widget-item.display div.topic h3, #help h3, div.widget-cart.modify h3, div.widget-order.receipt h3, #sidebar div#customer div.customer h3', { fontFamily: 'Garaline', hover: true });
		
		// DIN Schrift
		Cufon.replace('ul.actions a.action, div.widget-cart a.action, #departments li a:not(li li a), ul.toggle a, div.widget-item.browse ul.pages strong, div.widget-item.browse ul.pages a', { fontFamily: 'DINSchrift', hover: true });
		
		// Reveal Text
		$('div.widget-item.browse ul.pages strong, div.widget-item.browse ul.pages a, ul.toggle a, h3.shop, #departments li a:not(li li a), div#cart h3, div.widget-alert h3, #title h2, div.widget-item.display div.topic h3, ul.actions a.action, #help h3, div.widget-cart.modify h3, div.widget-order.receipt h3, #sidebar div#customer div.customer h3').css('visibility', 'visible');
	
	}
	

/* FUNCTION: KILL TABS
----------------------------------------------------------------------------- */ 


	function killTabs() {

		// REMOVE EMPTY JAVASCRIPT TAB AND PANE
		$('div.tabbed').not(".static, .ajax").children('ul.tabs').children('li').each(function() {

			var pane = $(this).children('a').attr('href');

			if ( $(this).parent().parent().find(pane).children('*').length == 0 ) {

				$(this).remove();
				$(this).parent().parent().find(pane).remove();

			}

		});

		// REMOVE TABBED PANEL
		$('div.tabbed').not(".static, .ajax").children('ul.tabs').each(function() {

			if ($(this).children('li').length == 0) {

				$(this).parent().remove();

			}

		});

	}


/* FUNCTION: INITIALIZE TABS
----------------------------------------------------------------------------- */


	function tabs() {

		// FEATURES BOX TABS
		if (page == 'index') {

			// Photos is the first tab, begin cycling
			if ( $('#photos').length > 0 && $('ul.tabs li:first-child a.tab').attr('href') == "#photos" ) {
				
				$('div#features > ul.tabs').tabs();
								
				$('#photos').addClass('pane').show();
			
				photoSlideshow();
				
				if ($('div#features div.widget-photo.slideshow ul.photos > li[class!=last]').length > 0) {

					$('div#features div.widget-photo.slideshow div a, a#photos_back, a#photos_next').hover(

						function() {

							$('a#photos_back').show();
							$('a#photos_next').show();

						}, function() {

							$('a#photos_back').hide();
							$('a#photos_next').hide();

						}

					)
				
				}
			
			}

			else {

				$('div#features > ul.tabs').tabs({
	
					fxSlide: false,
	
					show: function() {
	
						// PHOTOS TAB
						if ($('#photos:visible').length > 0) {
	
							$('#video div.flash div').empty();
							$('#radio div.flash div').empty();
	
							photoSlideshow();
	
							$('div#features div.widget-photo.slideshow div a, a#photos_back, a#photos_next').hover(
			
								function() {
	
									$('a#photos_back').show();
									$('a#photos_next').show();
	
								},
								function() {
	
									$('a#photos_back').hide();
									$('a#photos_next').hide();
	
								}
	
							)
	
						} 
	
						// RADIO TAB
						else if ($('#radio:visible').length > 0) {
	
							$('#video div.flash div').empty();
	
							photoSlideshow();
	
							var radio_player = $('#radio div.flash div').attr('id');
							window[radio_player]();
	
						}
	
						// VIDEO TAB
						else if ($('#video:visible').length > 0) {
	
							$('#radio div.flash div').empty();
	
							photoSlideshow();
	
							var video_player = $('#video div.flash div').attr('id');
							eval(video_player)();
	
						}
						
						else {
							
							
						}
	
					}
					
				});

			}

		}
		
		// THEN & NOW TABS
		if (page == 'then_and_now') {
			
			// Exclusive Photos is the first tab, begin cycling
			if ( $('#exclusive-photos div.widget-photo').length > 0 && $('ul.tabs li:first-child a.tab').attr('href') == "#exclusive-photos" ) {

				$('div#media > ul.tabs').tabs();
						
				$('#exclusive-photos').addClass('pane').show();
			
				photoSlideshow();
				
				if ($('div#media div.widget-photo.slideshow ul.photos > li[class!=last]').length > 0) {
					
					$('div#media div.widget-photo.slideshow div a, a#exclusive-photos_back, a#exclusive-photos_next').hover(
							
						function() {
						
							$('a#exclusive-photos_back').show();
							$('a#exclusive-photos_next').show();

						}, function() {
						
							$('a#exclusive-photos_back').hide();
							$('a#exclusive-photos_next').hide();

						}

					)

				}
			
			}

			// Photos is the first tab, begin cycling
			else if ( $('#photos').length > 0 && $('ul.tabs li:first-child a.tab').attr('href') == "#photos" ) {
				
				$('div#media > ul.tabs').tabs();
								
				$('#photos').addClass('pane').show();
			
				photoSlideshow();
				
				if ($('div#media div.widget-photo.slideshow ul.photos > li[class!=last]').length > 0) {

					$('div#media div.widget-photo.slideshow div a, a#photos_back, a#photos_next').hover(

						function() {

							$('a#photos_back').show();
							$('a#photos_next').show();

						}, function() {

							$('a#photos_back').hide();
							$('a#photos_next').hide();

						}

					)
				
				}
			
			}

			else {

				$('div#media > ul.tabs').tabs({
					
					fxSlide: false,
	
					show: function() {
	
						// EXCLUSIVE PHOTOS TAB
						if ($('#exclusive-photos:visible').length > 0) {
						
							$('#exclusive-video div.flash div').empty();
							$('#video div.flash div').empty();
							
							photoSlideshow();
							
							if ($('div#media div.widget-photo.slideshow ul.photos > li[class!=last]').length > 0) {
																													
								$('div#media div.widget-photo.slideshow div a, a#exclusive-photos_back, a#exclusive-photos_next').hover(
										
									function() {
									
										$('a#exclusive-photos_back').show();
										$('a#exclusive-photos_next').show();
	
									},
									function() {
									
										$('a#exclusive-photos_back').hide();
										$('a#exclusive-photos_next').hide();
	
									}
	
								)
								
							}
	
						}
						
						// EXCLUSIVE VIDEOS TAB
						else if ($('#exclusive-videos:visible').length > 0) {
	
							$('#videos div.flash div').empty();
	
							photoSlideshow();
	
			
							if ($('#exclusive-videos div.widget-media').length > 0) {
																	
								var exclusive_video_player = $('#exclusive-videos div.flash div').attr('id');
								eval(exclusive_video_player)();
															
							}
	
						}
	
						// PHOTOS TAB
						else if ($('#photos:visible').length > 0) {
							
							$('#exclusive-video div.flash div').empty();
							$('#video div.flash div').empty();
							
							photoSlideshow();
							
							if ($('div#media div.widget-photo.slideshow ul.photos > li[class!=last]').length > 0) {
	
								$('div#media div.widget-photo.slideshow div a, a#photos_back, a#photos_next').hover(
			
									function() {
	
										$('a#photos_back').show();
										$('a#photos_next').show();
	
									},
									function() {
	
										$('a#photos_back').hide();
										$('a#photos_next').hide();
	
									}
	
								)
								
							}
	
						}
	
						// VIDEOS TAB
						else if ($('#videos:visible').length > 0) {
	
							$('#exclusive-videos div.flash div').empty();
	
							photoSlideshow();
							
							if ($('#videos div.widget-media').length > 0) {
	
								var video_player = $('#videos div.flash div').attr('id');
								eval(video_player)();
								
							}
							
						}
						
						else {
							
							
						}
	
					}
					
				});
			
			}

		}

		// JAVASCRIPT TABS
		$('div.tabbed').not("#features, .ajax, .static, #media").children('ul.tabs').tabs({

			fxSlide: false,

			click: function() {

			}, load: function() {

				truncate();

			}, show: function() {

				truncate();

			}

		});

		// AJAX TABS
		$('div.tabbed.ajax > ul.tabs').tabs({

			fxSlide: false,

			click: function() {

				loading('start');

			}, load: function() {

				truncate();
				loading('stop');
				chat();

			}, show: function() {

				truncate();
				loading('stop');
				chat();

			}

		});

	}
	
