/* 
   houtekamer.com
	
   Javascript for default.css and iphone.css templates 
 
   Current functions:

   1. detect browser (css_browser_selector)
   2. detect if running on iPhone, if so 
        set orientation
        set window width to 417 (landscape width)
   3. call .css for PC's (default.css) or iPhone (iphone.css) 
   

*/

/* CSS Browser Selector v0.3.4 (Sep 29, 2009) 
   Rafael Lima (http://rafael.adm.br)
   http://rafael.adm.br/css_browser_selector
   License: http://creativecommons.org/licenses/by/2.5/
   Contributors: http://rafael.adm.br/css_browser_selector#contributors
*/

function css_browser_selector(u){var ua = u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1;},g='gecko',w='webkit',s='safari',o='opera',h=document.getElementsByTagName('html')[0],b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3.5')?g+' ff3 ff3_5':is('firefox/3')?g+' ff3':is('gecko/')?g:is('opera')?o+(/version\/(\d+)/.test(ua)?' '+o+RegExp.$1:(/opera(\s|\/)(\d+)/.test(ua)?' '+o+RegExp.$2:'')):is('konqueror')?'konqueror':is('chrome')?w+' chrome':is('iron')?w+' iron':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?'mobile':is('iphone')?'iphone':is('ipod')?'ipod':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win':is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}; 

css_browser_selector(navigator.userAgent);

if((navigator.userAgent.match(/iPhone/i))){
 /* updateOrientation checks the current orientation, sets the body's class attribute to portrait,   
    landscapeLeft, or landscapeRight */
 function updateOrientation()
 {
 	var orientation=window.orientation;
 	switch(orientation)
 	{
 		case 0:
 				/* If in portrait mode, sets the body's class attribute to portrait. 
 				   Consequently, all style definitions matching the body[class="portrait"] declaration
 				   in the iPhone.css file will be selected and used to style "Handling iPhone or iPod touch Orientation Events". */
 				document.body.setAttribute("class","portrait");
 				break;
 		case 90:
 				document.body.setAttribute("class","landscapeLeft");
 				break;
 		case -90:	
 				document.body.setAttribute("class","landscapeRight");
 				break;
 	}

 }

 // Point to the updateOrientation function when iPhone switches between portrait and landscape modes.
 window.onorientationchange=updateOrientation;
 updateOrientation;

 // style sheets
 document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"/iphone.css\" />");
 document.write("<meta name=\"viewport\" content=\"width=417\"/>");
}
else {
	document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"/default.css\" />");
	document.write("<meta name=\"viewport\" content=\"width=800\"/>");
}
