//var qsParm = new Array();
//function qs() {
//	var query = window.location.search.substring(1);
//	var parms = query.split('&');
//	for (var i=0; i<parms.length; i++) {
//		var pos = parms[i].indexOf('=');
//		if (pos > 0) {
//			var key = parms[i].substring(0,pos);
//			var val = parms[i].substring(pos+1);
//			qsParm[key] = val;
//		}
//	}
//} 
//qs();
//// JavaScript Document
//	var ua = navigator.userAgent ;
//	if (ua.indexOf("iPhone") > 0 && qsParm["full"] != 1) {
//		document.location.replace("iphone/default.asp");
//	}
		
//overlay sizes
var owidth = 848;
var oheight = 480;
var opad = 27;
var oHtotal = oheight + 2 * opad;
var oWtotal = owidth + (2*opad);

function getSize(vWidth) {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  if(vWidth) {
	  return myWidth;
  } else {
	  return myHeight;
  }
}

function resizeBG() {
	$("#mainBg").height(getSize(false));
	$("div#overlay").css("left",Math.max(0, ($(window).width() - oWtotal) / 2));
	$("div#overlay").css("top",Math.max(0, ($(window).height() - oHtotal) / 2));
	if (getSize(true) < oWtotal) {
		$("div#overlay").width(getSize(true)-(2*opad));
		$("#videoPlayer").width(getSize(true)-(2*opad));
		$("#videoPlayerE").width(getSize(true)-(2*opad));
	} else {
		$("div#overlay").width(owidth);
		$("#videoPlayer").width(owidth);
		$("#videoPlayerE").width(owidth);
	}
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function clearText() {
 if (document.InviteAFriend.YourMessage.value == "How far will you go to find the truth? Believe:879 - He is Among Us") {
  document.InviteAFriend.YourMessage.value = "";
 } else {
  document.InviteAFriend.YourMessage.select();
 }
}
 
function checkText() {
 if (document.InviteAFriend.YourMessage.value == "") {
  document.InviteAFriend.YourMessage.value = "How far will you go to find the truth? Believe:879 - He is Among Us";
 }
}


//var videoPlayerHTML = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" name="videoPlayer" width="848" height="480" align="middle" id="videoPlayer"> ';
//videoPlayerHTML += '<param name="allowScriptAccess" value="always" /> ';
////videoPlayerHTML += '<param name="flashVars" value="mediaURL=rtmp://calvalb.fcod.llnwd.net/a3536/o33/promos/believe879_teaser250.flv,378|promos/believe879_teaser500.flv,628|promos/believe879_teaser1000.flv,1128|promos/believe879_teaser1500.flv,1628&buffer=2&imageURL=images/flash/teaser_th.jpg&streamType=MBR&autoPlay=true&playerWidth=1000&playerHeight=563&autoHideControls=true&autoHideTime=5&initialVolume=50" /> ';
//videoPlayerHTML += '<param name="flashVars" value="mediaURL=http://www.believe879.com/video/Believe879_Teaser1500.flv&buffer=2&imageURL=http://www.believe879.com/images/teaser_th.jpg&streamType=Progressive&autoPlay=true&playerWidth=848&playerHeight=480&autoHideControls=true&autoHideTime=2&initialVolume=75" /> ';
//videoPlayerHTML += '<param name="movie" value="images/flash/LLNWPlayer.swf" /><param name="quality" value="high" /><param name="allowFullScreen" value="true" /> ';
//videoPlayerHTML += '<param name="bgcolor" value="#000000" /> ';
//videoPlayerHTML += '<embed src="images/flash/LLNWPlayer.swf" width="848" height="480" align="middle" allowfullscreen="true" quality="high" bgcolor="#000000" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashVars="mediaURL=rtmp://calvalb.fcod.llnwd.net/a3536/o33/promos/believe879_teaser250.flv,378|promos/believe879_teaser500.flv,628|promos/believe879_teaser1000.flv,1128|promos/believe879_teaser1500.flv,1628&buffer=2&imageURL=images/flash/teaser_th.jpg&streamType=MBR&autoPlay=true&playerWidth=1000&playerHeight=563&autoHideControls=true&autoHideTime=5&initialVolume=50" name="videoPlayerE" id="videoPlayerE" /> ';
//videoPlayerHTML += '</object>';

var videoPlayerHTML = '<OBJECT id=ply height="480" width="848" classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000>';
videoPlayerHTML += '<PARAM NAME="FlashVars" VALUE="file=/videos/Believe879_Teaser1500.flv&amp;image=/videos/Believe879_Teaser1500.jpg&amp;autostart=true&amp;controlbar=over&amp;backcolor=#333333&amp;frontcolor=#FFFFFF"><PARAM NAME="Movie" VALUE="/images/flash/player-v.swf"><PARAM NAME="Src" VALUE="/images/flash/player-v.swf"><PARAM NAME="Play" VALUE="0"><PARAM NAME="Loop" VALUE="-1"><PARAM NAME="Quality" VALUE="High"><PARAM NAME="AllowScriptAccess" VALUE="always"><PARAM NAME="Scale" VALUE="NoScale"><PARAM NAME="AllowNetworking" VALUE="all"><PARAM NAME="AllowFullScreen" VALUE="true">';
videoPlayerHTML += '<embed width="848" height="480" flashvars="file=/videos/Believe879_Teaser1500.flv&amp;image=/videos/Believe879_Teaser1500.jpg&amp;autostart=true&amp;controlbar=over&amp;backcolor=#333333&amp;frontcolor=#FFFFFF" allowscriptaccess="always" allowfullscreen="true" quality="high" bgcolor="#" name="ply" id="ply" style="" src="/images/flash/player-v.swf" type="application/x-shockwave-flash"/>';
videoPlayerHTML += '</OBJECT>';



$(function() {
    $("a[rel]").overlay({ 
 
        expose: {
			color: 'black', 
			onClose: function() {
				$("div.wrap").empty();
			}
		},
        effect: 'apple', 
 
        onBeforeLoad: function() { 
			this.getConf().top = Math.max(0, ($(window).height() - oHtotal) / 2);
			$("div.wrap").html(videoPlayerHTML);
			
		}, 		
		onClose: function() {
			$("div.wrap").empty();
		}
 
    }); 
	$('#InviteAFriend').bind('submit', function() {
		$(this).ajaxSubmit({
			target: '#overlayShare #wrap',
			url: '/includes/shareResults.asp?type=ajax'
		});
		$('#loading').show();
		return false; 
	});
});

function loadVideoAuto() {
	$("a[rel]").overlay({ 
        expose: 'black', 
        effect: 'apple', 
        onBeforeLoad: function() { 
			this.getConf().top = Math.max(0, ($(window).height() - oHtotal) / 2);
			$("div.wrap").html(videoPlayerHTML);
			
		}, 		
		onClose: function() {
			$("div.wrap").empty();
		},
		api: true
    }).load(); 
}

$(document).ready(function(){
	$(".share span").hover(function(){
		$(".shareBody", this).fadeIn("fast");},
		function() { }
	);
	if (document.all) {
		$(".share span").hoverClass("sfHover");
	}
	touchScroll('contentWrap');
});

$.fn.hoverClass = function(c) {
	return this.each(function(){
		$(this).hover(
			function() { $(this).addClass(c);  },
			function() { $(this).removeClass(c); }
		);
	});
};

function isTouchDevice(){
	try {
		if (document.all) {
			return false;
		} else {
			document.createEvent("TouchEvent");
			return true;
		}
	} catch(e) {
		return false;
	}
}
function touchScroll(id){
if(isTouchDevice()){ //if touch events exist...
var el=document.getElementById(id);
var scrollStartPos=0;
document.getElementById(id).addEventListener("touchstart", function(event) {
scrollStartPos=this.scrollTop+event.touches[0].pageY;
},false);
document.getElementById(id).addEventListener("touchmove", function(event) {
this.scrollTop=scrollStartPos-event.touches[0].pageY;
event.preventDefault();
},false);
}
} 
