var ua = navigator.userAgent.toLowerCase();
var browser = jQuery.browser;
var webkit = safari = opera = msie = mozilla = ipad = iphone = flash = android = winmobile = false;
if(browser.flash) { flash = true; }
if(browser.webkit) { webkit = true; }
if(browser.safari) { safari = true; }
if(browser.opera) { opera = true; }
if(browser.msie) { msie = true; }
if(browser.mozilla) { mozilla = true; }
if(ua.indexOf("ipad") > -1) { ipad = true; }
if(ua.indexOf("iphone") > -1) { iphone = true; }
if(ua.indexOf("android") > -1) { android = true; }
if(ua.indexOf("iemobile") > -1) { winmobile = true; }

/*
jQuery.browser.flash //Flash
jQuery.browser.sl //Silverlight
jQuery.browser.pdf /PDF format
jQuery.browser.java //Java
jQuery.browser.qtime //Quicktime
jQuery.browser.wmp //Windows Media Player
jQuery.browser.shk //Shockwave
jQuery.browser.rp //Realplayer
*/

$(document).ready(function() {
	$('#debug').html(flash + ":");
	if((ipad) || (iphone)) {
		$('#video span').html("I own Apple stuff as well, but some things are just not going to work on your device, sorry :(");
		$('.left-panel .panel-content').prepend("<h1>iPhone/iPad</h1><p>Lot's of Flash stuff here &amp; you are using an Apple device. Not a lot you can click on :(</p>");
	}
	if(flash) {
		$('.nav-options').hide();
	}

	//$(this).find('nav').addClass("nav");
	//$(this).find('header').addClass("heading");

});

var loadedobjects=""
var rootdomain="http://"+window.location.hostname
//var movebool = false;
//var rootdomain=window.location.hostname

function ap(url, containerid){
//movebool = true;
//moveup(50);
move();	
	
var randomnumber=Math.floor(Math.random()*999)
var newurl = url+"?"+randomnumber;
//alert(newurl);

var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
} 
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.onreadystatechange=function(){
loadpage(page_request, containerid);

}
page_request.open('GET', newurl, true)
page_request.send(null)
}

function loadpage(page_request, containerid) {
	if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
	document.getElementById(containerid).innerHTML=page_request.responseText
	var rand=Math.floor(Math.random()*10001);
	loadobjs("../css/sifr.css","../js/sifr.js","../js/sifr-debug.js","../js/sifr-config.js?"+rand+"");
}

function loadobjs(){
	if (!document.getElementById) {
		return
	}
	for (i=0; i<arguments.length; i++){
		var file=arguments[i]
		var fileref=""
	
		if (loadedobjects.indexOf(file)==-1) { //Check to see if this object has not already been added to page before proceeding
			if (file.indexOf(".js")!=-1) { //If object is a js file
				fileref=document.createElement('script')
				fileref.setAttribute("type","text/javascript");
				fileref.setAttribute("src", file);
			} else if (file.indexOf(".css")!=-1) { //If object is a css file
				fileref=document.createElement("link")
				fileref.setAttribute("rel", "stylesheet");
				fileref.setAttribute("type", "text/css");
				fileref.setAttribute("href", file);
			}
		}
		//if (fileref!="") { use to be here
	}
		if (fileref!="") { // pulled this out of for loop for sIFR
			document.getElementsByTagName("head").item(0).appendChild(fileref)
			loadedobjects+=file+" " //Remember this object as being already added to page
		}

}

function move() { window.scrollTo(0,50); }

/*
function moveup(anchorPoint) {
	
	if(movebool == true) {
		movebool = false;
		moveInterval = setInterval("moveup(50)",1);
	}
	// Check Which Browser
	
	if (navigator.appName == "Microsoft Internet Explorer"){ //for IE
		if (document.body.scrollTop) {
                                //for IE 5 & 5.5
		       var position = document.body.scrollTop;
		} else {
		       //for IE 6
		       var position = document.documentElement.scrollTop; 
		}
	}
	else {
                         //for Netscape, Opera
		var position = window.pageYOffset; 
	}


	//Keep scrolling down until reach this number: anchorPoint
	if (position <= anchorPoint) {
		//Set to final 'anchorPoint' destination
		window.scrollTo(0,anchorPoint);
		//Stops setInterval calling to function: DONE
		clearInterval(moveInterval);
		
		//alert("interval cleared at postion");
		
	} else { //keep scrolling down

		position -= 50;
		
		//Scroll to this x, y position in browser window
		window.scrollTo(0,position);

		//return true;
	}
	//alert("postion: "+position+" and anchorPoint is: "+anchorPoint);
}*/

