/* CLAY AIKEN */
/* Common Javascript
----------------------------------------------------------------------------- */


	$(window).load(function() {

		$('#content').animate({ height: 'show', opacity: 'show' }, 3000);

		$('#panel-comments ul #firstcomment').each(function() { 

			var $this = $(this); 
			$this.attr('href', $this.attr('href') + '#makecomment'); 
	
		}); 

		$('#firstcomment').click(function() {

			$('#panel-comments > ul').tabsClick(2);

		});

		if ($("div.widget-comment.modify").length == 0) {
			$('div#panel-comments').hide();
		}

	});


/* NAVIGATION
----------------------------------------------------------------------------- */


	var flashPlayer;
	
	if ( environment.lastIndexOf( "silverback" ) != -1 ) {
	
		environment = "http://www.clayonline.com";
		
	}
			
	var header_so = new SWFObject( asset_host + "/flash/clay_header.swf", 'headerskies', "730", "329", "9", "#FFFFFF" );

	header_so.addParam( "allowScriptAccess", "always" );
	header_so.addVariable( "xml", asset_host + "/xml/nav.xml" );
	header_so.addVariable( "feedLoc", asset_host + "/xml/bannerFeed.xml" );
	header_so.addVariable( "page" , page );
	header_so.addVariable( "path", asset_host +'/' );
	header_so.addVariable( "loggedin", loggedin );
	header_so.addVariable( "environment", environment );
	
	header_so.useExpressInstall( asset_host +  '/flash/expressinstall.swf');
	
	if ( page != "index" || loggedin == "true" ) {
	
		//header_so.write( "header" );
		
	}

	var splash_so = new SWFObject( asset_host + "/flash/clay_header_splash.swf", 'splashheader', "730", "487", "9", "#FFFFFF" );

	splash_so.addParam( "allowScriptAccess", "always" );
	splash_so.addVariable( "xml", asset_host + "/xml/nav.xml" );
	splash_so.addVariable( "feedLoc", asset_host + "/xml/bannerFeed.xml" );
	splash_so.addVariable( "path", asset_host +'/' );
	splash_so.addVariable( "environment", environment );
	
	splash_so.useExpressInstall( asset_host +  '/flash/expressinstall.swf');
	
	if ( page == "index" && loggedin == "false" ) {
	
		//splash_so.write( "splash-header" );
		
	}
	
	if ( page == "holiday" ) {
		var ecardAsset = "http://widgets.clearspring.com/o/493d6551218320c0/493d6551218320c0/-/-/-PUR/http%3A%2F%2Fwidgets.clearspring.com%2Fc%2Fwidget.bs?";
		var ecard_so = new SWFObject( ecardAsset, 'ecardSWF', "100%", "100%", "9", "#FFFFFF" );
		ecard_so.write( "ecard" );
	}

	function radio() {
	
		window.open ("/radio","radio","left=20,top=20,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=375,height=298");
	
	}


/* TABS
----------------------------------------------------------------------------- */


	$(document).ready(function() {
	
		if (section == "clay") {
	
			$('#panel-about > ul').tabs({ fxSlide: false });
			$('#panel-blog > ul').tabs({ fxSlide: false });
			$('#panel-media > ul').tabs({ fxSlide: false });
			$('#panel-questions > ul').tabs({ fxSlide: false });
			$('#panel-comments > ul').tabs({ fxSlide: false });
	
		} else if (section == "news") {
	
			$('#panel-news > ul').tabs({ fxSlide: false });
			$('#panel-comments > ul').tabs({ fxSlide: false });
	
		} else if (section == "contests") {
	
			$('#panel-contests > ul').tabs({ fxSlide: false });
	
		} else if (section == "friends") {
	
			$('#panel-friends > ul').tabs({ fxSlide: false });
	
		} else if (section == "useyourvoice") {
	
			$('#panel-give > ul').tabs({ fxSlide: false });
	
		} else if (section == "events") {
	
			$('#panel-events > ul').tabs({ fxSlide: false });
			$('#panel-comments > ul').tabs({ fxSlide: false });
			$('#panel-rsvp > ul').tabs({ fxSlide: false });
			$('#panel-spamalot > ul').tabs({ fxSlide: false });
	
		} else if (section == "extras") {
	
			$('#panel-extras > ul').tabs({ fxSlide: false });
	
		} else if (section == "media") {
	
			$('#panel-media > ul').tabs({ fxSlide: false });
			$('#panel-comments > ul').tabs({ fxSlide: false });
	
		} else if (section == "members") {
	
			$('#panel-about > ul').tabs({ fxSlide: false });
			$('#panel-blog > ul').tabs({ fxSlide: false });
			$('#panel-comments > ul').tabs({ fxSlide: false });
			$('#panel-photos > ul').tabs({ fxSlide: false });
			$('#panel-fans > ul').tabs({ fxSlide: false, cache: false });
	
		} else if (section == "photos") {
	
			$('#panel-comments > ul').tabs({ fxSlide: false });
			$('#panel-photos > ul').tabs({ fxSlide: false });
	
		} else if (section == "help") {
	
			$('#panel-answers > ul').tabs({ fxSlide: false });
			$('#panel-requirements > ul').tabs({ fxSlide: false });
	
		} else if (section == "useyourvoice") {
	
			$('#panel-news > ul').tabs({ fxSlide: false });
	
		} else if (page == "index") {
	
			$('#panel-news > ul').tabs({ fxSlide: false });
			$('#panel-fans > ul').tabs({ fxSlide: false });
	
		}
	
	
	/* Fix Pagination */
	
	
		if (page == "news") {
	
			$('#news-archive ul.pages a').each(function() { 
	
				var $this = $(this); 
				$this.attr('href', $this.attr('href') + '#news-archive'); 
	
			});
	
		} else if (page == "story") {			
	
			$('#comments ul.pages a').each(function() { 
	
				var $this = $(this); 
				$this.attr('href', $this.attr('href') + '#comments'); 
	
			});
	
		} else if (page == "event") {			
	
			$('#going ul.pages a').each(function() { 
	
				var $this = $(this); 
				$this.attr('href', $this.attr('href') + '#going'); 
	
			});
	
			$('#comments ul.pages a').each(function() { 
	
				var $this = $(this); 
				$this.attr('href', $this.attr('href') + '#comments'); 
	
			});
	
		} else if (page == "page") {			
	
			$('#archive ul.pages a').each(function() { 
	
				var $this = $(this); 
				$this.attr('href', $this.attr('href') + '#archive'); 
	
			});
	
			$('#comments ul.pages a').each(function() { 
	
				var $this = $(this); 
				$this.attr('href', $this.attr('href') + '#comments'); 
	
			});
	
		} else if (page == "friends") {		
	
			$('#good-friends ul.pages a').each(function() { 
	
				var $this = $(this); 
				$this.attr('href', $this.attr('href') + '#good-friends'); 
	
			});
	
			$('#friends ul.pages a').each(function() { 
	
				var $this = $(this); 
				$this.attr('href', $this.attr('href') + '#friends'); 
	
			});
	
		} else if (page == "update") {			
	
			$('#archive ul.pages a').each(function() { 
	
				var $this = $(this); 
				$this.attr('href', $this.attr('href') + '#archive'); 
	
			});
	
		} else if (page == "contests") {			
	
			$('#contest-archive ul.pages a').each(function() { 
	
				var $this = $(this); 
				$this.attr('href', $this.attr('href') + '#contest-archive'); 
	
			});
	
		} else if (page == "photo") {			
	
			$('#comments ul.pages a').each(function() { 
	
				var $this = $(this); 
				$this.attr('href', $this.attr('href') + '#comments'); 
	
			});
	
		} else if (page == "clip") {			
	
			$('#comments ul.pages a').each(function() { 
	
				var $this = $(this); 
				$this.attr('href', $this.attr('href') + '#comments'); 
	
			});
	
		} else if (page == "clay") {
	
			$('#archive ul.pages a').each(function() { 
	
				var $this = $(this); 
				$this.attr('href', $this.attr('href') + '#archive'); 
	
			});
	
			$('#photos ul.pages a').each(function() { 
	
				var $this = $(this); 
				$this.attr('href', $this.attr('href') + '#photos'); 
	
			});
	
			$('#claytv ul.pages a').each(function() { 
	
				var $this = $(this); 
				$this.attr('href', $this.attr('href') + '#claytv'); 
	
			});
	
			$('#audio ul.pages a').each(function() { 
	
				var $this = $(this); 
				$this.attr('href', $this.attr('href') + '#audio'); 
	
			});
	
			$('#friends ul.pages a').each(function() { 
	
				var $this = $(this); 
				$this.attr('href', $this.attr('href') + '#friends'); 
	
			});
	
			$('#questions ul.pages a').each(function() { 
	
				var $this = $(this); 
				$this.attr('href', $this.attr('href') + '#questions'); 
	
			});
	
		}
	
	});


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


	$(window).load(function() {

		if (section == "store") {

			tabs('removeEmptyTabs');
			truncate();
			paging();

			// PLUGIN: CLIQUE ACTIONS (Replaces submit buttons with text links)
			try { $('input[type=submit]').cliqueActions(); } catch (error) { alert('Error: Missing Clique Actions Plugin'); }
			
			// 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'); } }

		}

	});