/* JANES' ADDICTION TEMPLATE */
/* Javascript Triggers and Custom Functions
----------------------------------------------------------------------------- */


	$(document).ready(function() {
	
		$('.widget-event.display a.tickets').attr('target','');
	
	});


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


	$(window).load(function() {


/* OPEN BUY TICKET LINKS IN NEW WINDOW
----------------------------------------------------------------------------- */	


		$('a.action.tickets').attr('target','');


/* STORE NAVIGATION DROPDOWN
----------------------------------------------------------------------------- */


	$('ul#navigation li:has(ul)').hover(function() {

		$(this).addClass('hover');

	}, function() {

		$(this).removeClass('hover');

	});
		

/* MARKUP CHANGES
----------------------------------------------------------------------------- */	


		$('.widget-editorial.headlines a.browse').text('Browse All News');
		$('#optin input.save').attr('value', 'Get Updates');
		$('#departments ul li').find("a:contains('Everything')").remove();
	

/* REPLACE SUBMIT BUTTONS
----------------------------------------------------------------------------- */	

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


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


		if (section == "store") {
	
			// 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: false,
				pressure: false,
				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: 'none' // 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'); } }
	
		}


/* FUNCTION CALLS
----------------------------------------------------------------------------- */	


		tabs();
		cufon();
		comments();
		toggle();
		headlineColors();
		placeholderText();
		twitter();
		if (page == "index") { removeYear(); }
		

/* END POST-LOAD FUNCTIONS
----------------------------------------------------------------------------- */


	});


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


	function tabs() {

		if (page == "index") {

			// Temporary fix when photos is the first tab, begin cycling
			if ( $('#shots').length > 0 && $('ul.tabs li:first-child a.tab').attr('href') == "#shots" ) {
				
				$('div#features > ul.tabs').tabs();
								
				$('#shots').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#shots_back, a#shots_next').hover(

						function() {

							$('a#shots_back').show();
							$('a#shots_next').show();

						}, function() {

							$('a#shots_back').hide();
							$('a#shots_next').hide();

						}

					)
				
				}
			
			}
		
		}

		// Javascript tabs
		$('div.tabbed').not(".static").children('ul.tabs').tabs({

			fxSlide: false,

			click: function() {

			}, load: function() {
			
				sifr();

			}, show: function() {

				sifr();

				if (page == "index") {

					// Photos tab
					if ($('#shots:visible').length > 0) {

						$('#video div.flash div').empty();

						photoSlideshow();

						$('div#features div.widget-photo.slideshow div a, a#shots_back, a#shots_next').hover(
		
							function() {

								$('a#shots_back').show();
								$('a#shots_next').show();

							},
							function() {

								$('a#shots_back').hide();
								$('a#shots_next').hide();

							}

						)

					} 

					// Videos tab
					else if ($('#videos:visible').length > 0) {

						photoSlideshow();

						if ($('#video div.flash a.prompt').length == 0 ) {
							$('#video div.flash').prepend('<a class="prompt" href="#">Play</a>');
							$('#video div.flash a.prompt').click(function() {
	
								var video_player = $('#video div.flash div').attr('id');
								eval(video_player)();
								return false;
							
							});
						}
						
					}

					else {

					}

				}

			}

		});


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

			fxSlide: false,

			click: function() {

				loading('start');

			}, load: function() {

				sifr();
				loading('stop');

			}, show: function() {

				sifr();
				loading('stop');

			}

		});
		
	}
	

/* FUNCTION: CUFON REPLACEMENTS
----------------------------------------------------------------------------- */


	function cufon() {

		var unit_bold = [ 'h2', 'h3', 'h4', '#departments ul li', '#presales p strong' ];

		Cufon.replace(unit_bold, { fontFamily: 'Unit Bold', hover: true });
		
		$(unit_bold.toString()).css('visibility', 'visible');
				
	}


/* FUNCTION: COMMENTS
--------------------------------------------------------------------------- */


	function comments() {

		// Adds cancel button functionality
		if ($('#comment').parent().siblings('ul.tabs').children().length > 1) {

			$('#comment a.cancel').click(function() {

				$('#comment textarea').val('');
				$('#comment').parent().siblings("ul.tabs").tabsClick(1);
				return false;

			});

		}

		// Removes cancel button if there's no comments yet
		else {

			$('#comment a.cancel').remove();

		}

	}
	

/* FUNCTION: TOGGLE
----------------------------------------------------------------------------- */

	
	function toggle() {

		$('#joinmailinglist').toggle(function() {
		
			$('.widget-subscribe').slideDown();
			$(this).text('Hide The Mailing List');
			return false;
			
			}, function () {
		
			$('.widget-subscribe').slideUp();
			$(this).text('Join The Mailing List');
			return false;
			
		});
		
		$('#follow').toggle(function() {
		
			$('#socialnetworks').slideDown();
			return false;
			
			}, function () {
		
			$('#socialnetworks').slideUp();
			
		});
		
	}


/* FUNCTION: ADD COLORS TO HEADLINES
----------------------------------------------------------------------------- */


	function headlineColors() {

		if (page == "index") {
			
			$('.widget-editorial.callout .headlines').find('li').children('a[href*="blog"]').each(function() {
				
				$(this).addClass('blog');
				
			});
			
			$('.widget-editorial.callout .headlines').find('li').children('a[href*="news"]').each(function() {
			
				$(this).addClass('news');
				
			});
			
		}

	}


/* FUNCTION: REMOVE YEAR COUNT
----------------------------------------------------------------------------- */


	function removeYear() {

		$('.widget-event td.date').each(function() {
		
			var date = $(this).children('strong').text();
			var date = date.split('/');
			
			var month = date[0];
			var day = date[1];
			var year = date[2];
			
			var date = month + '/' + day;
			var date = $(this).children('strong').text(date);

		});
		
		$('.widget-editorial strong').each(function() {
		
			var date = $(this).text();
			var date = date.split('/');
			
			var month = date[0];
			var day = date[1];
			var year = date[2];
			
			var date = month + '/' + day;
			var date = $(this).text(date);

		});


	}


/* CHANGE PLACEHOLDER TEXT
----------------------------------------------------------------------------- */


	function placeholderText() {


		// Past events
		$('#past .placeholder p').text('Archived dates will come shortly.');
		$('#page-past .placeholder p').text('Archived dates will come shortly.');

		// Add title to radio player
		$('#radio').append('<p>click play to turn on radio</p>');
		$('#radio a.play').click(function() {
		
			$('#radio p').hide();
		
		});
		
	}
	
	
/* TWITTER FEED
----------------------------------------------------------------------------- */

	function twitter() {

		$("div#twitter").tweet({

        	username: "perryfarrell",
          	count: 1,
          	loading_text: "Loading tweets..."

     	 });

	}



/* REMOVE LINKS FROM COMMENTS
----------------------------------------------------------------------------- 


	function removeLinks() {

		$('#features .player div.details a').click(function() {
		
			return false;
			
		});
		
		$('#comments a.picture').removeAttr('href');
		$('#shots div a').removeAttr('href');
		$('#comments div.post strong span a').removeAttr('href');

	} */