$(function(){
	checkBrowserWidth();
	
	_screen = getBrowserWidth();
	//inserto flash
	var page = document.getElementById('page-box');
	var _body = page.parentNode;
	
	if (_body.id.split('-')[0] == 'hotel') insertFlash(_body.id);
	else insertInnerFlash(_body.id);

});


function insertFlash(swf)
{
		var _flash = false;
		if(_screen < 1000) _flash = { movie:"../swf/" + swf + "_800.swf", width:"736", height:"335", majorversion:"6", build:"0", wmode:"transparent" };
		else _flash = { movie:"../swf/" + swf + "_1024.swf", width:"974", height:"410", majorversion:"6", build:"0", wmode:"transparent" }

		if(true) UFO.create(_flash, "flash-box");
}

function insertInnerFlash(swf)
{
		var _flash = false;
		if(_screen < 1000) _flash = { movie:"../swf/" + swf + "_800.swf", width:"482", height:"329", majorversion:"6", build:"0", wmode:"transparent" };
		else _flash = { movie:"../swf/" + swf + "_1024.swf", width:"620", height:"410", majorversion:"6", build:"0", wmode:"transparent" };

		if(true) UFO.create(_flash, "flash-box");
}

function initPage()
{
	var page = document.getElementById('page-box');
	_screen = getBrowserWidth();
	if(page)
	{
		var _body = page.parentNode;
		if(_screen < 1000)
		{
			
			//$('head').append('<style media="all" type="text/css">@import "../css/all-800.css";</style>');
			//$('head').append('<!--[if lt IE 7]><link rel="stylesheet" type="text/css" href="../css/ie6-800.css" media="screen"/><![endif]-->');
			//$('head').html( $('head').html() + '<style media="all" type="text/css">@import "../css/all-800.css";</style>' );
			//$('head').html( $('head').html() + '<!--[if lt IE 7]><link rel="stylesheet" type="text/css" href="../css/ie6-800.css" media="screen"/><![endif]-->' );
			
			_body.innerHTML = _body.innerHTML + '<style media="all" type="text/css">@import "../css/all-800.css";</style>';
			if (navigator.userAgent.indexOf('MSIE')+1 && !navigator.userAgent.indexOf('MSIE 7')+1) _body.innerHTML = _body.innerHTML + '<style media="all" type="text/css">@import "../css/ie6-800.css";</style>';
			//if ($.browser.msie && )
			//_body.innerHTML = _body.innerHTML + '<!--[if lt IE 7]><link rel="stylesheet" type="text/css" href="../css/ie6-800.css" media="screen"/><![endif]-->';
		}
		
		if (_body.id.split('-')[0] == 'hotel') insertFlash(_body.id);
		else insertInnerFlash(_body.id);

	}

}

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;
}

/*if (window.addEventListener)
{
	window.addEventListener("load", initPage, false);
}
else if (window.attachEvent)
{
	window.attachEvent("onload", initPage);
}*/



/*
 *	This code is adapted by Marcio Barrios (http://www.marciobarrios.com)
 *	from The Man in Blue Resolution Dependent Layout Script (http://www.themaninblue.com/experiment/ResolutionLayout/)
 */
var menos800;
function checkBrowserWidth()
{
	var theWidth = getBrowserWidth();
	
	
	if (theWidth == 0)
	{
		var resolutionCookie = document.cookie.match(/(^|;)tmib_res_layout[^;]*(;|$)/);
		menos800 = "0";

		if (resolutionCookie != null)
		{
			setStylesheet(unescape(resolutionCookie[0].split("=")[1]));
			
		}
		
		/*$(document).ready(function(){
			checkBrowserWidth();
		});*/
				
		//return false;
	}

	if (theWidth < 1000)
	{
		setStylesheet("all-800");
		document.cookie = "tmib_res_layout=" + escape("all-800");
		
		//si es < IE7
		if (navigator.userAgent.indexOf('MSIE')+1 && navigator.userAgent.indexOf('MSIE 7')==-1) {
			setStylesheet("ie6-800");
			document.cookie = "tmib_res_layout=" + escape("ie6-800");
		}
		
		menos800 = "1";

		document.cookie = "tmib_res_layout=" + escape("all-800");
	}
	else
	{
		setStylesheet("");
		document.cookie = "tmib_res_layout=";
	}
	
	//return true;
};



function setStylesheet(styleTitle)
{
	var currTag;
	
	ie6 = (styleTitle == 'ie6-800') ? true : false;
	
	if (document.getElementsByTagName)
	{
		for (var i = 0; (currTag = document.getElementsByTagName("link")[i]); i++)
		{
			if (currTag.getAttribute("rel").indexOf("style") != -1 && currTag.getAttribute("title"))
			{
				currTag.disabled = true;
				
				if (currTag.getAttribute("title") == 'all-800' && ie6)
				{
					currTag.disabled = false;
				}
				
				if(currTag.getAttribute("title") == styleTitle)
				{
					currTag.disabled = false;
				}
				if(currTag.getAttribute("title") == "default")
				{
					currTag.disabled = false;
				}
			}
		}
	}
	
	return true;
};

