//config variables for javascript
var CONFIG = {
	minWidth: 980,
	minHeight: 630
	/*
	URL1: "http://www.yourdomain.com/page1.html",
	URL2: "http://www.yourdomain.com/page2.html"
	*/
};

var flashObj;

//some common functions
function pageOnLoad(minWidth,minHeight) {
	getFlashObj();
	CONFIG.minWidth = minWidth;
	CONFIG.minHeight = minHeight;
}

function getFlashObj() {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        flashObj = window["home"];
    }
    else {
        flashObj = document["home"];
    }
}

function redirectUrl(url, trackname){	
	if(trackname){		
		ecTrack(trackname);
	}
	window.location.href=url;
}

function openUrl(url){
	window.open(url);
}

function openWinAndTrack(url,trackname,winOptions){
	ecTrack(trackname);
	if(winOptions){
		window.open(url,"newWin",winOptions);
	}else{
		window.open(url);
	}
}

/*
*	Get GET parameters on the url
*/
function queryString(key) {
	hu = window.location.search.substring(1);
	gy = hu.split("&");
	for (i=0;i<gy.length;i++) {
		ft = gy[i].split("=");
		if (ft[0] == key) {
			return ft[1];
		}
	}
}
function ecTrack(code){
	//trace("ecTrack "+code);
	//pageTracker._trackPageview(code);
	wtTrack(code);
}

function wtTrack(tag){
	// use the following for webtrend
	dcsMultiTrack("DCS.dcsuri",tag, "WT.ti",tag);				
}

function track(tag){
	// use the following for google analytics
	_gaq.push(['_trackPageview', tag]); 
}

function trace(message){
	try{
		console.log(message);
	}catch(e){}
}

function fbLogin(){
	FB.login(function(response) 
	{
		if (response.session) {	  
			// logged in				
			document.getElementById("flashContent").onConnected(response.session.uid, response.session.access_token, response.perms);
			if (response.perms) {
			} else {
			  
			}
		} else {
			//not logged in
			document.getElementById("flashContent").onNotConnected();
		}
	}, {perms:'publish_stream'});
}

function fbPublish(photo, caption, link, name,message, description){
	FB.api('/me/feed', 'post', {picture:photo,message:message,link:link,name:name,caption:caption,description:description}, 	function(response) {
		if (!response || response.error) {
			alert('Error occured');
		} else {
		}
	});
}

function fbShare(){
	var url = "http://www.facebook.com/sharer.php?u="+location.href;
	openWinAndTrack(url, "","toolbar=no,width=700,height=450,top=0, left=0 ,directories=0,status=0,scrollbars=yes,resizable=yes,menubar=0");	
}

function getViewport(type){
	var viewportwidth;
	var viewportheight;
	 
	 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	 
	 if (typeof window.innerWidth != 'undefined')
	 {
		  viewportwidth = window.innerWidth,
		  viewportheight = window.innerHeight
	 }
	 
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

	 else if (typeof document.documentElement != 'undefined'
		 && typeof document.documentElement.clientWidth !=
		 'undefined' && document.documentElement.clientWidth != 0)
	 {
		   viewportwidth = document.documentElement.clientWidth,
		   viewportheight = document.documentElement.clientHeight
	 }
	 
	 // older versions of IE
	 
	 else
	 {
		   viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
		   viewportheight = document.getElementsByTagName('body')[0].clientHeight
	 }
	 
	 if(type == 'width') return viewportwidth;
	 else return viewportheight;
}

function windowResized(){
	if (document.getElementById("flashContent") != undefined){
		
		var viewportwidth;
		var viewportheight;
		 
		 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
		 if (typeof window.innerWidth != 'undefined')
		 {
			  viewportwidth = window.innerWidth,
			  viewportheight = window.innerHeight
		 }
		 
		// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
		 else if (typeof document.documentElement != 'undefined'
			 && typeof document.documentElement.clientWidth !=
			 'undefined' && document.documentElement.clientWidth != 0)
		 {
			   viewportwidth = document.documentElement.clientWidth,
			   viewportheight = document.documentElement.clientHeight
		 }
		 
		 // older versions of IE
		 else
		 {
			   viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
			   viewportheight = document.getElementsByTagName('body')[0].clientHeight
		 }

		if(viewportwidth < CONFIG.minWidth){
			document.getElementById("flashContent").style.margin="0px 0px 0px 0px";
			document.getElementById("flashContent").width = CONFIG.minwidth;
		}else{
			document.getElementById("flashContent").style.margin="0px 0px 0px 0px";
			document.getElementById("flashContent").width = viewportwidth;
		}
		
		if(viewportheight< CONFIG.minHeight){
			document.getElementById("flashContent").style.margin="0px 0px 0px 0px";
			document.getElementById("flashContent").height = CONFIG.minHeight;
		}else{
			document.getElementById("flashContent").style.margin="0px 0px 0px 0px";
			document.getElementById("flashContent").height = viewportheight;
		}
	}
}
