/*
	
	Designed & Developed by Systemagic
	www.systemagic.co.uk
	
*/

$(document).bind("ready", function(){
				   
	$('body').addClass("javascript");	

	$('div.signup input#name').attr("revert", "Name");
	$('div.signup input#email').attr("revert", "Email address");
	
	$('div.signup input[type=text]').bind("focus", function(){
		if($(this).val() == $(this).attr("revert")){
			$(this).val("");
		}
		
		$(this).addClass("filled");
	});
	
	$('div.signup input[type=text]').bind("blur", function(){
		if($(this).val() == ""){
			$(this).val($(this).attr("revert")).removeClass("filled");
		}
	});

	$('.clickable').bind("click", function(){
		if($(this).find("a[rel=click]").attr("target") != "_blank"){
			window.location = $(this).find("a[rel=click]").attr("href");
		}else{
			window.open($(this).find("a[rel=click]").attr("href"));
		}
		
		event.preventDefault();
		event.stopPropagation();		
		return false;
	});
	
	jQuery.fn.extend({
		getCurrentAndNext: function(filter){
			current = $(this).find(filter + "[current]");
			
			len  = $(this).find(filter + "[current]").next(filter).length;
			if(len >= 1){
				next = $(this).find(filter + "[current]").next(filter);
			}else{
				next = $(this).find(filter + ":first");
			}
			
			$(current).removeAttr("current");
			$(next).attr("current", "true");
			
			return [current, next];
		}
	});
	
	$.banner = {};
	
	$('.banner .controls a:first').addClass("selected");
	$('.banner img').css("display", "none");
	$('.banner img:first').css("display", "block");
	
	$(".banner .controls a").bind("click", function(){
		$(this).parent().find(".selected").removeClass("selected");
		$(this).addClass("selected");
		$.i = parseFloat($(this).html());
		
		current = $(".banner img[current]");
		
		$(current).removeAttr("current").fadeOut(400);
		$(".banner").find("img").eq($.i).attr("current", "true").fadeIn(400);
		
		clearInterval($.banner);
		$.banner = setInterval(updateBanner, 5000);		
	});
	
	if($('.banner').length){

		$('.banner img:not(:first)').fadeOut(0);
		$('.banner img:first').attr("current", "true");
		
		updateBanner = function(){
			nextCurrent = $('.banner').getCurrentAndNext("img");
			
			current = nextCurrent[0];
			next	= nextCurrent[1];
			
			$(current).fadeOut(400);
			$(next).fadeIn(400);
			
			$("a[rel="+ $(current).attr("id") +"]").removeClass("selected");
			$("a[rel="+ $(next).attr("id") +"]").addClass("selected");
		}
		
		$.banner = setInterval(updateBanner, 5000);
	}
	
	$('div.banner div.controls').each(function(){
		$(this).css("left", Math.floor(480 - (($(this).children().length * 19)/2)));
	});
	
	$("div.map").hover(function(){
		$(this).find("img:last").addClass("active").stop().fadeIn(200);
	}, function(){
		$(this).find("img:last").stop().fadeOut(200, function(){
			$(this).addClass("active");
		});
	});
	
	$('div.signup form').bind("submit", function(){
		$.ajax({
			type: "POST",
			url: $(this).attr("action"),
			data: $(this).serialize(),
			dataType: 'json',
			success: function(data){
				if(data.success){
					$('div.signup > *').fadeOut(200, function(){
						$('div.signup h3').html("Thank you for joining!");
						$('div.signup p').html("Thank you for signing up for our email newsletter, we will be in touch soon!");
						$('div.signup').addClass("success");
						$('div.signup > *').not("form").fadeIn(200);
					});
				}
			}
		});
		
		event.preventDefault();
		event.stopPropagation();
		
		return false;
	});
	
/*	$('.open-mypage').click(openToggle);
	
	function openToggle() {
	    $('#mypage-info').slideToggle('2000', "linear", function () {
	        
	    });
    	$('.open-mypage').replaceWith('<a class="close-mypage">Hide Concert Details &raquo;</a>');
    	$('.close-mypage').click(closeToggle);
    };
    
    function closeToggle() {
	    $('#mypage-info').slideToggle('2000', "linear", function () {
	        
	    });
    	$('.close-mypage').replaceWith('<a class="open-mypage">Show Concert Details &raquo;</a>');
    	$('.open-mypage').click(openToggle);
    };
    
*/


	
});
