var currConcert = 1;
var currConcertOver;
var canClick = true;

$(document).ready(function(){

	if (playerVersion != undefined && playerVersion >= 9) {
		var flashvars = {
			var_xml:"/xml/run/xml_coverflow/"
		};
		var params = {wmode:"transparent"};
		swfobject.embedSWF("swf/albums.swf", "albums_container", "390", "475", "9.0.0","/swf/expressInstall.swf", flashvars, params);
	}
	
	$(".concerts_row").each(function(){
		$(this).css("cursor", "pointer");
		$(this).click(function(){
			window.location = $(".concert_row_link", $(this)).attr("href");
		});
		
		$(this).mouseover(function(){
			currConcertOver = $(this).attr("class");
			$(this).attr("class","concerts_row concerts_row_over");
		});
		
		$(this).mouseout(function(){
			$(this).attr("class",currConcertOver);
		});
		
	});
	
	// Newsletter Optin
	$("#newsletter_search_field").focus(function(){
		if ($(this).val() == "Your e-mail address")
		$(this).val("");
	});
	$("#newsletter_search_field").blur(function(){
		if ($(this).val() == "")
		$(this).val("Your e-mail address");
	});
	$("#newsletter_submit_button").click(function(){
		if (isValidEmailAddress($("input[name=n_email]").val()))
		{
			var label;
			var concerts;
			
			if ($("#n_concerts").attr("checked") == true)
			concerts = 1;
			else
			concerts = 0;

			if ($("#n_label").attr("checked") == true)
			label = 1;
			else
			label = 0;
			
			var optin = $.ajax({
				type: "POST",
				url: "/ajx/run/ajx_newsletterOptin/",
				data: "email="+$("input[name=n_email]").val()+"&"+"label="+label+"&concerts="+concerts,
				success: function(xml){
					var res = $(xml).find('res').text();
					var msg = $(xml).find('msg').text();
					if (res)
					{
						jAlert(msg, 'Newsletters');
					}
					else
					{
						jAlert("email not added or updated. Try again later.", 'Error');
					}
				}
			})
			setTimeout(function(){
				if ( optin ){
					optin.abort();
				}
			}, 5000); 
		} else {
			jAlert("Invalid email format.", 'Error');
		}
	});
});
	
function isValidEmailAddress(emailAddress) 
{
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(emailAddress);
}
function concerts_control(direction)
{
	var pos = (parseInt(($("#concerts_rows").css("margin-top")).toString().replace("px","")));
	var lim = ($(".concerts_row").size() - 4) * -110;
	
	if (direction == "up" && pos > lim && canClick == true)
	{
		canClick = false;
		var goTo = (pos - 110)+"px";
		$("#concerts_rows").animate({"margin-top": goTo}, "slow", function() {
			canClick = true;
		});
		
	}
	if (direction == "down" && pos < 0 && canClick == true)
	{
		canClick = false;
		var goTo = (pos + 110)+"px";
		$("#concerts_rows").animate({"margin-top": goTo}, "slow", function() {
			canClick = true;
		});
		
	}
}
