//Cambio dinámico de hoja de estilos dependiendo de la resolución

// Title : Dynamic Resolution Dependent Layout Demo
// Author : Kevin Hale
// URL : http://particletree.com

function getBrowserWidth()
{
    if (window.innerWidth) {
        return window.innerWidth;
	} else if (document.documentElement && document.documentElement.clientWidth != 0) {
        return document.documentElement.clientWidth;
	} else if (document.body) { 
		return document.body.clientWidth;
	}
	
    return 0;
}

function dynamicLayout()
{
    var browserWidth = getBrowserWidth();

    if (browserWidth < 900) {
        setActiveStyleSheet("ancho800");
    } else {
        setActiveStyleSheet("");
    }
}

//Stylesheet functions

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;
    }
  }
}


//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 dynamicLayout function when page loads and when it resizes.
addEvent(window, 'load', dynamicLayout);
addEvent(window, 'resize', dynamicLayout);
