//find query attached
var pageLoc = String(document.location);
var queryPos = pageLoc.indexOf("?");
var queryString = (queryPos < 0) ? "" : pageLoc.substring(queryPos);

function getQueryVariable(variable) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		if (pair[0] == variable) {
			return pair[1];
		}
	}
}

// browser and os detect
var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;

if (checkIt('safari')) browser = "safari"
else if (checkIt('msie')) browser = "msie"
else if (!checkIt('compatible')) browser = "ns"
else browser = "unknown";

if (checkIt('windows')) os = "pc"
else if (checkIt('mac')) os = "mac"
else os = "unknown";

function checkIt(string){
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}

//popup
function popup( url, w, h, windowName, r, s ) {
	win = window.open(url, windowName, 'height=' +h+ ', width=' +w+ ', resizable=' +r+ ', status=no, scrollbars=' +s+ ', location=no, menubar=no, toolbar=no, left=50, top=50');
	win.focus();
}
function popupFull( url, w, h, windowName, r, s ) {
	win = window.open(url, windowName, 'height=' +h+ ', width=' +w+ ', resizable=' +r+ ', status=no, scrollbars=' +s+ ', location=no, menubar=yes, toolbar=no, left=50, top=50');
	win.focus();
}

if (getQueryVariable('game') == 'tractor_tippin' || getQueryVariable('game') == 'tractor_tipping'){
	popGame('tractor_tippin');
}
else if (getQueryVariable('game') == 'ramones_body_shop'){
	popGame('ramones_body_shop');
}
else if (getQueryVariable('game') == 'desert_dash'){
	popGame('racing');
}
else if (getQueryVariable('game') == 'poster'){
	popGame('poster');
}
else if (getQueryVariable('game') == 'coloring_book'){
	popGame('coloring_book');
}
else if (getQueryVariable('game') == 'lizzies_curio_shop'){
	popGame('lizzies_curio_shop');
}
else if (getQueryVariable('game') == 'maters_memory'){
	popGame('maters_memory');
}
else if (getQueryVariable('game') == 'luigis_tire_shop'){
	popGame('luigis_tire_shop');
}
else if (getQueryVariable('game') == 'flos_v8'){
	popGame('flos_v8');
}
else if (getQueryVariable('game') == 'video_game'){
	popGame('video_game');
}
else if (getQueryVariable('game') == 'trading_cards'){
	popGame('trading_cards');
}

//action tag
function actionTag(page){
	var actionLoad = 'http://switch.atdmt.com/action/';
	document.action_tag.src = actionLoad + page;
}

//view trailer - pass me the number
//popTrailer(2);
function popTrailer(number){
	switch(number){
		case 1: //trailer
			popup('http://www.totaleclips.com/player/splash.aspx?custid=3&playerid=2&clipid=e27900', 360, 480, 'trailer', 'no', 'no');//pre
			//popup('http://www.totaleclips.com/player/splash.aspx?custid=3&playerid=2&clipid=e27901', 360, 480, 'trailer', 'no', 'no');//post
			hitbox.Set_hbPageView('trailer', '/cars/multimedia/trailers;/multimedia/pixar+animation/cars/trailers');
			break;
		case 2: //music video
			popup('http://www.totaleclips.com/player/splash.aspx?custid=3&playerid=2&clipid=e27902', 360, 480, 'trailer', 'no', 'no');
			track('highway+mvideo');
			break;
		default:
			break;
	}
}

function popGame(name){
	switch(name){
		case 'ramones_body_shop':
			popup('us/games/ramones/index.html', '770', '550', 'Ramones', 0, 0);
			break;
		case 'racing':
			popup('us/games/desert_dash/index.html', '750', '554', 'Racing', 0, 0);
			break;
		case 'tractor_tippin':
			popup('us/games/tractor_tippin/index.html', '750', '544', 'Tractor_Tipping', 0, 0);
			break;
		case 'tractor_tipping'://just in case
			popup('us/games/tractor_tippin/index.html', '750', '544', 'Tractor_Tipping', 0, 0);
			break;
		case 'poster':
			popup('us/games/games_poster.html', '750', '644', 'games_poster', 0, 0);
			break;
		case 'coloring_book':
			popup('us/games/games_color.html', '750', '644', 'games', 0, 0);
			break;
		case 'lizzies_curio_shop':
			popup('us/games/games_curio.html', '750', '644', 'games', 0, 0);
			break;
		case 'maters_memory':
			popup('us/games/memory_game.html', '750', '644', 'games', 0, 0);
			break;
		case 'luigis_tire_shop':
			popup('us/games/games_luigi.html', '750', '644', 'games', 0, 0);
			break;
		case 'flos_v8':
			popup('us/games/flos.html', '750', '644', 'games', 0, 0);
			break;
		case 'video_game':
			//this is a download
			break;
		case 'trading_cards':
			//this is an external link in the same window
			break;
		default:
			break;
	}
}

//order now link
//orderNow();
function orderNow(){
	hitbox.Set_hbLink('Exit_cars_order_dvd');
	win = window.open('http://go-disneyshopping.com/CarsWSDVD');
	//actionTag('061024_Cars_OrderNow');
}

//order bluray link
function orderBluray(){
	hitbox.Set_hbLink('Exit_cars_order_bluray');
	win = window.open('http://disneyshopping.go.com/webapp/wcs/stores/servlet/DSIProductDisplay?langId=-1&storeId=10051&catalogId=10002&productId=1212162&categoryId=13693&CMP=OTL-TWDC_BVHE&att=BVHE');
	//popup('http://disneyvideos.disney.go.com/moviefinder/calltoorder.html', 380, 265, 'calltoorder', 'no', 'no');
}

function gotoPage(page){
	switch(page){
		case 'soundtrack':
			location.href = 'main.html?sec=7';
			break;
		case 'aboutdvd':
			location.href = 'main.html?sec=4';
			break;
		case 'showroom':
			location.href = 'main.html';
			break;
		case 'splash':
			location.href = 'index.html';
			break;
		case 'mobile':
			hitbox.Set_hbLink('Exit_cars_SYNERGY_mobile');
			openDisclaimer('http://cars.av.net')
			break;
		case 'license':
			ltow = window.open('http://disney.go.com/disneyvideos/animatedfilms/cars/licensetowin', 'license');
			ltow.focus();
			break;
		case 'about_bluray':
			hitbox.Set_hbLink('Exit_cars_learn+more+about+bluray');
			location.href = 'http://disney.go.com/disneyvideos/bluray/index.html?section=about';
			break;
		case 'tour':
			hitbox.Set_hbLink('Exit_cars_bluray+mall+tour');
			location.href = 'http://disney.go.com/disneyvideos/bluray/index.html?section=tour';
			break;
		default:
			break;
	}
}

function gotoCountry(country, url){
	country = country.replace(' - ', '+');
	country = country.replace(' ', '+');
	country = country.replace('-', '');
	//alert(country);
	hitbox.Set_hbLink('Exit_cars_CHOOSE+COUNTRY_'+ country);
	openWindow(url);
}

function trackCar(car){
	trackStateFarmAd();
	hitbox.Set_hbPageView(car.toLowerCase(), "/cars/about/char;/about/pixar+animation/cars/char");
}

function trackStateFarmAd(){
	//alert('ad reloaded');
	var sfaddiv = document.getElementById('sfad');
	var flash_embed = '';
	flash_embed += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" height="72" width="180">';
	flash_embed += '<param name="movie" value="swf/sf_ad.swf">';
	flash_embed += '<param name="quality" value="best">';
	flash_embed += '<param name="play" value="true">';
	flash_embed += '<param name="wmode" value="transparent">';
	flash_embed += '<embed height="72" pluginspage="http://www.macromedia.com/go/getflashplayer" wmode="transparent" src="swf/sf_ad.swf" type="application/x-shockwave-flash" width="180" quality="best" play="true">';
	flash_embed += '</object>';
	sfaddiv.innerHTML = flash_embed;
}

//disclaimer
function openDisclaimer(URL){
	win = window.open('http://disney.go.com/disneyvideos/javascript/disclaimer/disclaimer.html?'+ URL, 'intermediate', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=370,height=210');
}

//You May Also Like
function ymal_ratatouille() {
	hitbox.Set_hbLink('exit_cars_synergy_ratatouille');
	location.href = "http://disney.go.com/disneyvideos/animatedfilms/ratatouille/";
}

function ymal_pixar() {
	hitbox.Set_hbLink('exit_cars_synergy_pixar+shorts');
	location.href = "http://disney.go.com/disneyvideos/pixarshorts/";
}

function ymal_carsRebate() {
	hitbox.Set_hbLink('exit_cars_synergy_rebate+offer');
	win = window.open('http://adisney.go.com/disneyvideos/animatedfilms/cars/pdf/Cars_Bluray_rebate.pdf');
}