// ATV Namespace
atv = {};
$(document).ready(function(){
	// Loop through initalitation object
	for(var i in atv.init){
		atv.init[i]();
	}
});

// Setup Main options
atv.options = {};
atv.options.gateway = "/services/ajax.cfc";



// Setup Init object
atv.init = {};

atv.init.browser = function(){
	if(jQuery.browser.mozilla){
		if(jQuery.browser.version.substring(0,3) == "1.8"){
			$("body").addClass("firefox2");
		} else {
			$("body").addClass("firefox3")
		}
	}
	if(jQuery.browser.msie){
		$("body").addClass("ie"+parseInt(jQuery.browser.version));
	}
	if(jQuery.browser.safari){
		$("body").addClass("safari");
	}
}


atv.strings = {};




atv.home = {};



/********** FMA *********/
atv.home.fma = {};
atv.home.fmatimer = {};
atv.home.settimer = function(){
	if(typeof(atv.home.fmatimer) == "number"){
		clearInterval(atv.home.fmatimer);
	}
	atv.home.fmatimer = window.setInterval(function() {
		atv.home.fma.next();
	}, 10000);
};
atv.home.fma.next = function(){
	var from = $("#fma .column.one .slides a.active");
	var toIndex = 0;
	if(parseInt(from.attr("pos"),10)+1 < $("#fma .column.one .slides a").length){
		toIndex = parseInt(from.attr("pos"),10)+1;
	}
	var to = $("#fma .column.one .slides a:eq("+toIndex+")");

	to.css("left","100%").show().animate({left: "0%"}, 250, "linear", function(){
		$(this).addClass("active");
	});
	from.animate({left:"-100%"}, 250, "linear", function(){
		$(this).hide().removeClass("active");
	});
};
atv.home.fma.back = function(){
	var from = $("#fma .column.one .slides a.active");
	var toIndex = parseInt(from.attr("pos"),10)-1;
	if(toIndex == -1){
		toIndex = $("#fma .column.one .slides a").length-1;
	}
	var to = $("#fma .column.one .slides a:eq("+toIndex+")");

	to.css("left","-100%").show().animate({left: "0%"}, 250, "linear", function(){
		$(this).addClass("active");
	});
	from.animate({left:"100%"}, 250, "linear", function(){
		$(this).hide().removeClass("active");
	});
};
atv.home.fma.watch = function(){
	window.location.href = $("#fma .column.one .slides a.active").attr("href");
};
atv.init.fma = function(){
	/******************
		FMA Sliders
	*******************/
	$("#fma .column.one .slides a")
		.each(function(i){
			$(this).attr("pos",i);
			if(i===0){
				$(this).show().addClass("active");
			} else {
				$(this).hide();
			}
		});

	$("#fma .column.one .nav a[href=#next]").click(function(){ atv.home.fma.next(); atv.home.settimer(); return false;});
	$("#fma .column.one .nav a[href=#back]").click(function(){ atv.home.fma.back(); atv.home.settimer(); return false; });
	$("#fma .column.one .nav a[href=#watch]").click(function(){ atv.home.fma.watch(); return false; });

	/* Auto Advance FMA */
	atv.home.settimer();	
};


