//

var currentSheet = "";
var deviceType = "DESKTOP";


deviceSpecific();

$(document).ready(function() {
    adjustStyle(func_viewportwidth());
	  window.onresize = function(){
        adjustStyle(func_viewportwidth());
    };
});

$(window).load(function() {
 
});


function func_viewportwidth(){
	var viewportwidth;
	
	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	if (typeof window.innerWidth != 'undefined')
	{
	  viewportwidth = window.innerWidth;
	}
	// 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;
	}
	// older versions of IE
	else
	{
	   viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
	}
	return viewportwidth;
}

function func_viewportheight(){
	var viewportheight;
	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	if (typeof window.innerWidth != 'undefined')
	{
	  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)
	{
	   viewportheight = document.documentElement.clientHeight
	}
	// older versions of IE
	else
	{
	   viewportheight = document.getElementsByTagName('body')[0].clientHeight
	}
	return viewportheight;
}
	 
function adjustStyle(width) {
    width = parseInt(width);
	if (deviceType == "DESKTOP"){
		if (width < 980){
			if (currentSheet == "Desktop"){
				setActiveStyleSheet('Tablet');
				document.getElementById("navLeft_wrapper").className = "navMenuAbsolute";
			}
			if (currentSheet == ""){
				setActiveStyleSheet('Tablet');
				document.getElementById("navLeft_wrapper").className = "navMenuAbsolute";
			}
		} else {
			if (currentSheet == "Tablet"){
				setActiveStyleSheet('Desktop');
			}
			if (currentSheet == ""){
				setActiveStyleSheet('Desktop');
			}
		}
		
		if (currentSheet == "Desktop"){
			var wheight = func_viewportheight();
			if (wheight < 540){
				document.getElementById("navLeft_wrapper").className = "navMenuAbsolute";
			}
			else
			{
				document.getElementById("navLeft_wrapper").className = "navMenuFixed";
			}
		}
	}
}


function deviceSpecific(){
	var ua = navigator.userAgent;
	var checker = {
	  iphone: ua.match(/(iPhone|iPod|iPad)/),
	  blackberry: ua.match(/BlackBerry/),
	  android: ua.match(/Android/)
	};
	if (checker.android){
		setActiveStyleSheet('Tablet');
		deviceType = "ANDROID";
	}
	else if (checker.iphone){
		setActiveStyleSheet('Tablet');
		deviceType = "IPHONE";
	}
	else if (checker.blackberry){
		setActiveStyleSheet('Tablet');
		deviceType = "BBERRY";
	}
	else {
		//desktop
	}
	//alert(deviceType);
}


function setActiveStyleSheet(title) {
   var i, a, main;
   for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
     if(a.getAttribute("rel").indexOf("style") != -1
        && a.getAttribute("title")) {
			if(a.getAttribute("title") == "STYLESHEETCS"){
				//this stylesheet is the valid one
				if (title == "Tablet"){
					a.setAttribute("href","styleTablet.css");
				}
				if (title == "Desktop"){
					a.setAttribute("href","styleDesktop.css");
				}
		    }
  
     }
   }
   currentSheet = title;
}

//
