$(document).ready(function(){

	$(".pod a.more").click(function(){
		$(this).hide();
		$(this).siblings(".close").show();
		$(this).siblings(".more").show();
		return false;
	});

	$(".pod a.close").click(function(){
		$(this).hide();
		$(this).siblings("div.more").hide();
		$(this).siblings("a.more").show();		
		return false;
	});	

	// $("#gramophone").click(playMusic);

	$(".comment_count a").click(showComments);	

	setLightBox();
	setFancyBox();	
	checkAVP();
	avpFormSubmit();

	resizeFrame();

	$('#player-container').blur(function(){
		document['tv-ad-holder'].triggerFadeOut();
	});	

	$('#player-container').focusout(function(){
		document['tv-ad-holder'].triggerFadeOut();
	});	

	if ($("li.gchoice_9_1 label").length > 0) {
		$("li.gchoice_9_1 label").html("I agree to the <a href=\"./terms-and-conditions/\">terms & conditions</a>");
	}

});

var musicPlaying;
var isFaded = false;

function playMusic() {
	if (musicPlaying == true) {
		stopMusic();
	} else {
		startMusic();
	}
}

function stopMusic() {
	$("#gramophone").removeClass("play");	
	$("#player").remove();
	musicPlaying = false;
	return false;
}

function startMusic() {
	$("#gramophone").addClass("play");
	$("body").append("<embed src=\"" + template_dir + "/music.mp3\" loop=\"0\" autostart=\"true\" id=\"player\" hidden=\"true\" />");
	musicPlaying = true;
	return false;	
}

function setLightBox() {
	$(".gallery-icon a").lightBox();
	$(".lightbox-me").lightBox();
}

function setFancyBox() {
	$(".fancybox-me").fancybox({'onComplete': resizeFancyBoxVideo});

	$(".fancybox-me.youtube").click(function() {
		$.fancybox({});

		return false;
	});

	$("#gallery a").fancybox({
		'onComplete': resizeFancyBoxGallery,
		'width': 640,
		'height': 360,
		'autoDimensions': false
	});

}

function resizeFancyBoxGallery() {
	$('#fancybox-wrap').width(640); return false;
}

function resizeFancyBoxVideo() {
	$('#fancybox-wrap').width(560); return false;
}

function showComments() {
	$("#comments-block").toggle();
}

function checkAVP() {
	if ($("#avp-form-link").length > 0) {
		$("#avp-form-link").fancybox({'modal' : true, 'width': 757, 'height': 346, 'autoDimensions': false});
		$('#fancybox-outer').width(757);		
		$("#content-right-inner").hide();
		$("#avp-form-link").trigger('click');
	}
}

function avpFormSubmit() {
	$("#avp-form").submit(function () {	
		$.post("/avp/", $(this).serialize(), function(data) {
			if(data > 0) {
				$("#avp-form h1").hide();			
				$("#content-right-inner").show();	
				$.fancybox.close();
				$("#avp-form").hide();					
			} else {
				window.location = "http://www.drinkaware.co.uk";
			}
		});
		return false;
	});
}


function fadeOut() {
}

function fadeIn() {

}

function resizeFrame() {
	var height = $(document).height();

	if (parent.location != window.location) {
		parent.resize(height);
	}
}

