var mobileBroadband = {

	disableSelectContent : false,
	disableFlashContentCall : false,

	tabs: {
		init: function(){
			$('.tab-content:not(:eq(0))').hide();
			$('.tab-nav li:eq(0)').addClass('active');
			$('.tab-nav a').click(function(){
				mobileBroadband.tabs.show($(this).attr('rel'));
				$('html, body').animate({
					scrollTop:($('.tabs').offset().top)+'px'
				})
				return false;
			});
		},
		show: function(id) {
			$('.tab-nav li').removeClass('active');
			$('.tab-nav a[rel=' + id + ']').parent().addClass('active');
			$('.tab-content').hide();
			$('#' + id).show();
		}
	},
	selectContent: function(name, fromflash) {	
		
		if(mobileBroadband.disableFlashContentCall == true && fromflash != false){
			mobileBroadband.disableFlashContentCall = false;
			return false;
		} else {
			if(!mobileBroadband.disableSelectContent){
				var url = '/shop/mobile-broadband?state=content&content=' + name;
				$.ajax({
					url: url,
					type: 'GET',
					dataType: 'html',
					success: function(data) {
						$("#content").html(data);
						showfaq();
					}
				})
			} else {
				mobileBroadband.disableSelectContent = false;
			}
			return false;
		}
		
	},
	selectProduct: function(id) {
		var url = '/shop/mobile-broadband?state=content&content=laptop&laptopId=' + id;;
		$.ajax({
			url: url,
			type: 'GET',
			dataType: "html",
			success: function(data) {
				$("#content").html(data);
			}
		})
		return false;
	},
	navigate: {
		changePage: function(name){
			mobileBroadband.changeFlash(name);		
		},
		changeFlash: function(name){
			mobileBroadband.flash.getMovie("InternetEverywhereMovie").sendNavVarToFlash(name);
		},
		showProduct: function(name){
			mobileBroadband.navigate.changeFlash("products");
			mobileBroadband.selectContent(name);	
		}
	},
	flash: {
		getMovie: function(name){
			var isIE = navigator.appName.indexOf("Microsoft") != -1;
			return (isIE) ? window[name] : document[name];
		}
	},
	getFlashMovie: function(movieName){
		var isIE = navigator.appName.indexOf("Microsoft") != -1;
		//alert(document[movieName].name);
		return (isIE) ? window[movieName] : document[movieName];
	},
	moveNavFlash: function(page){
		mobileBroadband.getFlashMovie("InternetEverywhereMovie").sendNavVarToFlash(page);
	},
	changePage: function(name){
		mobileBroadband.moveNavFlash(name);
		mobileBroadband.selectContent(name);
	},
	showProducts: function(name){
		mobileBroadband.disableFlashContentCall = true;
		mobileBroadband.moveNavFlash("products");
		mobileBroadband.selectContent(name, false);
	},
	showProduct: function(id){
		mobileBroadband.disableFlashContentCall = true;
		mobileBroadband.moveNavFlash("products");
		mobileBroadband.selectProduct(id);
	},
	showDongleNotFlash: function(id){
		mobileBroadband.selectContent(id);
	},
	showProductNotFlash: function(id){
		mobileBroadband.selectProduct(id);
	}
};

$(function(){
	$(".flashlink").live("click", function(){
		mobileBroadband.moveNavFlash($(this).attr('rel'));
		return false;
	});
});
$(function(){
	$(".flashlink1").live("click", function(){
		mobileBroadband.changePage($(this).attr('rel'));
		return false;
	});
});
$(function(){
	$(".flashlink2").live("click", function(){
		mobileBroadband.showProduct($(this).attr('rel'));
		return false;
	});
});
$(function(){
	$(".flashlink3").live("click", function(){
		mobileBroadband.showProducts($(this).attr('rel'));
		return false;
	});
});
$(function(){
	$(".flashlink4").live("click", function(){
		mobileBroadband.selectContent($(this).attr('rel'));
		return false;
	});
});
$(function(){
	$(".flashlink5").live("click", function(){
		mobileBroadband.showProductNotFlash($(this).attr('rel'));
		return false;
	});
});
$(function(){
	$(".flashlink6").live("click", function(){
		mobileBroadband.showDongleNotFlash($(this).attr('rel'));
		return false;
	});
});

function showProductFromFlash(productID){
	var arrIndex = productID.replace("product","")
	var productRelArr = [];	
	productRelArr[1] = "dongle" // Dongles
	productRelArr[2] = "83800" //Samsung N130 black
	productRelArr[3] = "75400" // Asus Eee PC 100HGO
	productRelArr[4] = "79000" //Compaq Mini 110	
	productRelArr[5] = "78700" // Toshiba L300
	if( arrIndex == 1 ){
		mobileBroadband.selectContent("dongle");
	}else{
		mobileBroadband.selectProduct(productRelArr[arrIndex]);
	}	
}



var loc = window.location.href;
var startsection = 0;

if(loc.indexOf("/mobile-broadband/why-choose-orange")!=-1){
	startsection = 1;
	mobileBroadband.disableFlashContentCall = true;
} else if (loc.indexOf("/mobile-broadband/products-and-prices")!=-1) {
	startsection = 2;
	mobileBroadband.disableFlashContentCall = true;
} else if (loc.indexOf("/show/laptop")!=-1) {
	startsection = 2;
	mobileBroadband.disableFlashContentCall = true;
} else if (loc.indexOf("/mobile-broadband/data-calculator")!=-1) {
	startsection = 3;
	mobileBroadband.disableFlashContentCall = true;
} else if (loc.indexOf("/mobile-broadband/help-and-faqs")!=-1) {
	startsection = 4;
	mobileBroadband.disableFlashContentCall = true;
} else if (loc.indexOf("/mobile-broadband/dongle")!=-1) {
	startsection = 2;
	mobileBroadband.disableFlashContentCall = true;
}

$(document).ready(function() {

	var so = new SWFObject("/flash/mobile-broadband/IEWPreloadWrapper.swf", "InternetEverywhereMovie", "570", "450", "7", "#ffffff");
	so.addParam("bgcolor", "#FFFFFF");
	so.addParam("wmode", "transparent");
	so.addParam('allowfullscreen','true');
	so.addVariable("startsection", startsection);
	//so.addParam("flashVars","startsection=3");
	so.write("mb_flash");

	var loc = window.location.href;
	if(loc.indexOf("/compaq_mini_700")!=-1){
		mobileBroadband.selectProduct("79000");
		mobileBroadband.disableSelectContent = true;
	} else if(loc.indexOf("/asus_1000h_go")!=-1){
		mobileBroadband.selectProduct("75400");
		mobileBroadband.disableSelectContent = true;
	} else if(loc.indexOf("/toshiba_l300")!=-1){
		mobileBroadband.selectProduct("78700");
		mobileBroadband.disableSelectContent = true;
	} else if(loc.indexOf("/Samsung_N310_black")!=-1){
		mobileBroadband.selectProduct("83800");
		mobileBroadband.disableSelectContent = true;
	} else if(loc.indexOf("/dongle")!=-1){
		mobileBroadband.selectContent("dongle");
		mobileBroadband.disableSelectContent = true;
	}	
});
