// JavaScript Document

	window.onload = setScreenClass; 
	window.onresize = setScreenClass;


//addEvent() by John Resig
function addEvent( obj, type, fn ){ 
   if (obj.addEventListener){ 
      obj.addEventListener( type, fn, false );
   }
   else if (obj.attachEvent){ 
      obj["e"+type+fn] = fn; 
      obj[type+fn] = function(){ obj["e"+type+fn]( window.event ); } 
      obj.attachEvent( "on"+type, obj[type+fn] ); 
   } 
} 

//Run setScreenClass function when page loads and when it resizes.
addEvent(window, 'load', setScreenClass);
addEvent(window, 'resize', setScreenClass);



	//  Following transition classes will be declared:

	//

	//	classname		  screenwidth

	//	------------------------------------------

	//	pda_v			  240px			

	//	pda_h			  320px			

	//	ultralow		  320px -  640px	

	//	screen_lo		  640px -  800px	

	//	screen_med		  800px - 1024px	

	//	screen_hi		 1024px - 1280px	

	//	screen_wide				> 1280px			



	function setScreenClass(){

		var fmt = document.documentElement.clientWidth;

//		var cls = (fmt<=240)?'pda_ver':(fmt>240&&fmt<=320)?'pda_hor':(fmt>320&&fmt<=640)?'screen_ultralow':(fmt>640&&fmt<=800)?'screen_low':(fmt>800&&fmt<=1024)?'screen_med':(fmt>1024&&fmt<=1280)?'screen_high':'screen_wide';

		var cls = (fmt<=580)?'pda':(fmt>580&&fmt<=680)?'super_narrow_screen':(fmt>680&&fmt<=780)?'narrower_screen':(fmt>780&&fmt<=880)?'narrow_screen':(fmt>880&&fmt<=980)?'medium_narrow_screen':(fmt>980&&fmt<=1080)?'medium_screen':(fmt>1080&&fmt<=1180)?'medium_wide_screen':(fmt>1180&&fmt<=1280)?'wide_screen':(fmt>1280)?'wider_screen':'wider_screen';

//		document.getElementById('count').innerHTML=fmt+'px -> '+cls;
		document.body.id=cls;

		document.body.className=cls;

//		document.getElementById('count').innerHTML=fmt+'px -> '+cls;

	};

//	function positionAudio(toggle){
//		document.body.id=toggle;
//		
//	};
	
//	function positionAudio(audioClass) {
//	
//	var currAudioClass = document.getElementByID("audioClip");
//	
//	currAudioClass.setAttribute("class", audioClass);
//	currAudioClass.setAttribute("className", audioClass);
//
//	return;
//	} 
//	
//	function setAudio(audioClass) {
//	
//	var currAudioClass = document.getElementByClassName(audioClass);
//	
//	currAudioClass.setAttribute("class", "setAudio");
//	currAudioClass.setAttribute("className", "setAudio");
//
//	return;
//	} 



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")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);
