//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];
		}
	}
}

//action tag
function actionTag(page){
	var actionLoad = 'http://switch.atdmt.com/action/';
	document.action_tag.src = actionLoad + page;
}

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');
}

//wallpapers - pass me the number and width
//wallpaper(2, 800);
function wallpaper(number, width){
	popup('wallpaper.html?number='+number+'&width='+width, 700, 500, 'wallpaper', 'yes', 'yes');
	//will pop wallpaper.html with image passed dynamically - image must be images/wallpapers/(width)_#.jpg
	//example: images/wallpapers/1024_1.jpg
}

//local listings
function listings(){
	popup('local_listings.html', 500, 400, 'listings', 'yes', 'yes');
}

//local listings
function feedback(){
	popup('feedback_cs.html', 550, 310, 'feedback', 'no', 'no');
	//popup('feedback_form.html', 500, 460, 'feedback', 'yes', 'yes');
}

//screensaver - pass me the os (win or osx)
//screensaver('win');
function screensaver(os){
	switch(os){
		case 'win': //windows
			popup('download_file.html?file=http://a.media.global.go.com/bvtv/accordingtojim/AccordingToJim_pc.exe.zip', 300, 250, 'download', 'no', 'no');//sp2 fix
			break;
		case 'osx': //osx
			popup('download_file.html?file=http://a.media.global.go.com/bvtv/accordingtojim/AccordingToJim_osx.sit', 300, 250, 'download', 'no', 'no');//sp2 fix
			break;
		default:
			break;
	}
}

//buddy icons
function buddyIcons(){
	popup('buddyicons.html', 550, 520, 'icons', 'no', 'no')
}

// 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;
}

//buddy icons
function buddyIcon(icon){
    var pagePath = "" + window.location;
    var pageRoot = pagePath.substring(0,pagePath.lastIndexOf("/")+1) + "images/icons/";
	var iconUrl = "aim:BuddyIcon?src="+pageRoot+icon;
	//var iconUrl = pageRoot+icon;
	if (os == 'pc')
		document.location = iconUrl;
	else alert ('This is a PC feature only.  Please click "Download Full Set".');
}

//download - pass me the file
//download('aimicons/icons.zip');
function download(file){
	popup('download_file.html?file='+file, 300, 250, 'download', 'no', 'no');//sp2 fix
	//alert(file);//test
}
