include('validation.js')

// apply to all png images 
$(document).ready(function(){
	jQuery = $

	$('.hide').hide()
	
	/* hide any open_flyout when user clicks somewhere */
	$('*').click(function() {
		if(execOnNextClick != null) {
			execOnNextClick()
		    execOnNextClick = null
		}
	})
	
	execOnNextClick = null
	
	// share flyouts
	$('.share_button').click(function() {
		if(this.innerHTML == '+ share') {	
			$(this.parentNode).find('ul').show()
			this.innerHTML = '- share'
			obj = this
			execOnNextClick = function() { $(obj.parentNode).find('ul').hide(); obj.innerHTML = '+ share' }
			return false
		}
	})
	
	// date filter flyout (photo_view.php)
	$('.date_filter_button').click(function() {
		obj = $(this.parentNode).find('ul').show()
		execOnNextClick = function() { obj.hide() }
		return false
	})

	
	// fbr flyout
	$('#fueledbyramen').click(function() {
						
		$('#fueledbyramen_flyout').show()
		
		  /*execOnNextClick = function() { 
		   //alert("flyout clicked2");
		
		       $('#fueledbyramen_flyout').hide(); return false
		      }*/
				
		return false
	})

	//$('a').ifixpng();
	//$('img').ifixpng();
	//$('div').ifixpng();
	//$('h1').ifixpng();
	

	//hide mailinglist popups when mouse moves out
	$('#header_mailinglist_popup, #footer_mailinglist_popup').click(
		function() {}, function(e) {	    
	    if(e.relatedTarget) {
    		$(this).hide()
	    }
	})

	$('#popup_close').click(function() {
		$('#header_mailinglist_popup').hide()
		
	})
	var displayFlag=true;	
	$('#mailinglist_link').click(function() {
		displayFlag=false;
		if(jQuery('#signupForm').css("display") == "block")
          		$('#signupForm').hide()
		else
			 $('#signupForm').show()
	})
	
	$('#signupForm').click(function() {			
		displayFlag=false;
		if(jQuery('#signupForm').css("display") == "block")	          		
			 $('#signupForm').show()
	})
	 
	$('.homePage').click(function() {
		if((jQuery('#signupForm').css("display") == "block") && displayFlag)
          		$('#signupForm').hide()		
          	displayFlag=true;	
	}) 
	
	 
	jQuery('.date_filter_button').click(function() { 
		if(jQuery('#dates_dropdown').css("display") == "block")
		  jQuery('#dates_dropdown').hide()
		else
		  jQuery('#dates_dropdown').show()
	})
	
	// Mailinglist
	$('.mailinglist .mailinglist_join').click(function() {
	    /* if(validate($(this.parentNode), 'mailinglist')) {
			document.mailSignupForm.submit();
			$('.mailinglist .form').hide();$('.mailinglist .thank_you').show()
			
	    }*/
	    
	     if(validateSignUpForm()) {	     	
	    	document.mailSignupForm.submit();
	    	$('.mailinglist .form').hide();	    	
	    	$('.mailinglist .thank_you').show();	    	
	    
	    }
	    
	    
	})
	
	
	
	//hide mobileAlert popups when mouse moves out
	$('#mobileAlerts_popup').click(
		function() {}, function(e) {	    
	    if(e.relatedTarget) {
		$(this).hide()
	    }
	})
	$('#mobileAlert_sidebar #mobile_popup_close').click(function() {
		if(jQuery('#mobileAlert_sidebar #mobileAlerts_popup').css("display") == "block")
			$('#mobileAlert_sidebar #mobileAlerts_popup').hide()
		
	})
	$('#cellstream #mobile_popup_close').click(function() {
		if(jQuery('#cellstream #mobileAlerts_popup').css("display") == "block")
			$('#cellstream #mobileAlerts_popup').hide()
			
	})
	$('#res_blog_home #mobile_popup_close').click(function() {
			if(jQuery('#res_blog_home #mobileAlerts_popup').css("display") == "block")
				$('#res_blog_home #mobileAlerts_popup').hide()
				
	})

	$('#mobile_popup_close').click(function() {
		$('#mobileAlerts_popup').hide()
		$('.mobileAlerts_popup').hide()
	})
	$('.getOnPhoneCellstream').click(function() {
		if(jQuery('#cellstream #mobileAlerts_popup').css("display") == "block"){
	  	 $('#cellstream #mobileAlerts_popup').hide()
	  	 }
		else{
		 $('#cellstream #mobileAlerts_popup').show()
		 mobile_click();
		 }
		 
	})	
	$('.getOnPhone').click(function() {
		if(jQuery('#mobileAlerts_popup').css("display") == "block"){
	  	 $('#mobileAlerts_popup').hide()
	  	 }
		else{
		 $('#mobileAlerts_popup').show()
		 mobile_click();
		 }
	})
	/*$('#res_blog_home .getOnPhoneBuzz').click(function() {
			if(jQuery('#res_blog_home #mobileAlerts_popup').css("display") == "block")
		  	 $('#res_blog_home #mobileAlerts_popup').hide()
			else
			 $('#res_blog_home #mobileAlerts_popup').show()
	})*/
	$('#getOnPhoneBuzz_sidebar').click(function() {
			if(jQuery('#mobileAlert_sidebar #mobileAlerts_popup').css("display") == "block"){
			 $('#mobileAlert_sidebar #mobileAlerts_popup').hide()
			 }
			else{
			 $('#mobileAlert_sidebar #mobileAlerts_popup').show()
			 mobile_click();
			 }
	})
	
	// Mailinglist
	$('.mobile .mailinglist_join').click(function() {
	    if(validate($(this.parentNode), 'mobilealert')) {
			document.mobileAlertForm.submit();
			$('.mobile .form').hide();$('.mobile .thank_you').show()

	    }
	})
	$('.mobile .mailinglistmobile_join').click(function() {
	    if(validate($(this.parentNode), 'mobilealert')) {
			document.mobileAlertForm.submit();
	    }
	})
	$('.mobile_buzz .mailinglist_join').click(function() {
		    if(validate($(this.parentNode), 'mobilealert')) {
				document.mobileAlertBuzz.submit();
				$('.mobile_buzz .form').hide();$('.mobile_buzz .thank_you').show()
	
		    }
	})
	$('.mobile_cellstream .mailinglist_join').click(function() {
		    if(validate($(this.parentNode), 'mobilealert')) {
				document.mobileAlertCellstream.submit();
				$('.mobile_cellstream .form').hide();$('.mobile_cellstream .thank_you').show()
	
		    }
	})
	$('.mobile_sidebar .mailinglist_join').click(function() {
		    if(validate($(this.parentNode), 'mobilealert')) {
				document.mobileAlertSidebar.submit();
				$('.mobile_sidebar .form').hide();$('.mobile_sidebar .thank_you').show()
	
		    }
	})
	//mobilealerts end
})

/* Add functions for lyric popup */
function include(url) {
    $('head').append('<script type="text/javascript" src="/components/scripts/' + url + '"/>')
}

function resizeImages(whichId, maxH) {
  if($(whichId).length) {
	  var pix=$(whichId).find('img');
	  
	  for (i=0; i<pix.length; i++) {
		w=pix[i].width;
		h=pix[i].height;
		 
		if (h > maxH) {
		  f=1-((h - maxH) / h);
		  pix[i].width=w * f;
		  pix[i].height=h * f;
		  $(pix[i]).parent().css({ "background":"#000" });
		}
		else {
		  $(pix[i]).css({ "padding-top": (maxH - h) / 2 + 'px'});	 
		}
	  }
  }
}

function fbs_click(url) 
{
	t=document.title;
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(url)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
	return false;
}

function mobile_click()
{
	var s=s_gi('wmg,wmgglobald2c,wmgd2cparamore');
	s.linkTrackVars='events,prop1,eVar4';
	s.linkTrackEvents='event17';
	s.prop1='Paramore';
	s.eVar4='Paramore';
	s.events='event17';
	s.tl(this,'o','Mobile Stream Popup');
}
