
/**
 * Version: 1.0.0
 * Copyright: TVCatchup Ltd
 * Author: Mason Jackson (m.jackson@tvcatchup.com)
 * Last update: March 31, 2009
 */

var requiredMajorVersion = 9;
var requiredMinorVersion = 0;
var requiredRevision = 124;

$(document).ready(function() {

	$(".submit").hover(
		function () {
			$(this).addClass("hover");
		},
		function () {
			$(this).removeClass("hover");
		}
	);

	/* modal window overlay */
	$('<div id="qtip-blanket">').css({
		position: 'absolute',
	    top: $(document).scrollTop(),
	    left: 0,
	    height: $(document).height(),
	    width: '100%',
	    opacity: 0.7,
	    backgroundColor: 'black',
	    zIndex: 5000
	}).appendTo(document.body).hide();

	/* modal window */
	var qtip = $(document.body).qtip({
		content: {
			title: {
	           	text: 'Loading ...',
	           	button: 'Close'
	       	},
	       	text: '<div id=\"modal\">Loading ...</div>',
		},
	    position: {
	       	target: $(document.body),
	       	corner: 'center'
	    },
	    show: false,
	    hide: false,
		style: {
	         width: 600,
	         padding: '14px',
	         border: {
	            width: 9,
	            radius: 9,
	            color: '#666666'
	         },
	         name: 'dark'
		},
	    api: {
	      	beforeShow: function() {
	           	//$('#qtip-blanket').fadeIn(this.options.show.effect.length);
	       	},
	       	beforeHide: function() {
	           	//$('#qtip-blanket').fadeOut(this.options.hide.effect.length);
	       	}
		}
	});

	// CHANNELS
	////////////////////////////////////////////////////////////////////////////////////////////////////

	$(".modal").click(function() {

		var channel = $(this).parent().attr("id").replace("ch_", "");
		var content = $("#beta").html().replace(/\?c=1/g, "?c=" + channel);

		var api = $(qtip).qtip("api");
		api.updateTitle("TVCatchup BETA");
		api.updateContent(content);
		api.show();

		return false;

	});

	// TV GUIDE
	////////////////////////////////////////////////////////////////////////////////////////////////////

	/* <select> */
	$("#days").change(function() {
		location.href = $(this).val();
	});

	/* re-order channels */
	$("#programmes").sortable({
		items: ".row",
		handle: ".logo",
		//containment: "#programmes",
		opacity: 0.6,
		update: function(event, ui) {
			$.ajax({
				type: "POST",
				url: "guide.html",
				data: "order=" + $("#programmes").sortable("toArray"),
				success: function(data, status) {
					//alert(data);
				}
			});
		}
	});

	/* disabled selection */
	$("#programmes").disableSelection();

	/* programmes */
	$(".programme").each(function() {
		$(this).qtip({
			content: {
				text: '<font color="#efefef">' + $(this).find(".tip").html() + '</font>'
			},
			show: 'mouseover',
			hide: 'mouseout',
			position: {
				target: "mouse",
				adjust: {x: 5, y: 5}
			},
			style: {
				padding: 2,
		      	background: '#252525',
		      	color: '#ffffff',
		      	'font-size': '11px',
		      	border: {
		         	width: 7,
		         	radius: 5,
		         	color: '#252525'
		      	},
		      	//tip: true,
		      	name: 'dark'
			}
		});
		
		/* onclick
		$(this).click(function() {

			var api = $(qtip).qtip("api");
			api.updateTitle($(this).find(".title").html());
			api.show();

			$.get("?modal=1", {
				channel: $(this).find(".channel").html(),
				start: $(this).find(".start").html(),
				end: $(this).find(".end").html()
			}, function(data) {
				$("#modal").html(data);
			});

		});*/

	});

});

