(function (window, bam, undef) {

	bam.loadSync(bam.homePath + "bam.datetime.js", bam.homePath + "bam.cookies.js", bam.homePath + "bam.url.js");
	
 	var 
		isDebug = ~document.location.search.indexOf("debug"),
		isIPad = bam.env.client.isIPad,
		isIPhone = bam.env.client.isIPhone,
		isIOS = (isIPad || isIPhone),
		cookieName = (isIPad) ? "gbtv_2011_ipad" : "gbtv_2011_iphone",
		cookie = bam.cookies.get(cookieName),
		cookieObj = { name: cookieName, value: "Redirect", expires: bam.datetime.DateTime(new Date()).incrementDate(+1), path: "/", domain: ".gbtv.com"},		
		refParam = bam.url.Location( window.location ).getParam( "ref" );
		
		
	if(isDebug){
		var msg = "";
		msg += "isIOS=" + isIOS;
		msg += ", isIPhone=" + isIPhone;
		msg += ", cookieName=" + cookieName;
		msg += ", cookie="+cookie;
		alert(msg);	
	}	
				
	if(isIOS && cookie === null && refParam !=="com.gbtv.iOS.Full"){
		bam.cookies.set(cookieObj);		
		document.location.href = "http://web.gbtv.com/choose_" + ((isIPhone)?"iphone.html":"ipad.html");
	}	

}(this, this.bam, undefined));


