var msie6 = $.browser.msie && /MSIE 6\.0/i.test(window.navigator.userAgent) && !/MSIE 7\.0/i.test(window.navigator.userAgent);

if (!msie6) {

	$(function(){
		var fadeInLogoSpeed=400,
			animateLogosSpeed=1200,
			curDelay=100,
			delayBuffer=200;
			
		//remove value from search field when focused on
		
		var searchText = "Title, Director, Actor, Studio, Keyword";
		
		$('input#searchField').focus(function() {
			$(this).attr('value','');
			$(this).css('font-style', 'normal');
			$(this).css('color', '#222');
		});
		$('input#searchField').blur(function(){
			if ($(this).attr('value') == '') {
				$(this).attr('value', searchText)
				$(this).css('font-style', 'italic');
				$(this).css('color', '#aaa');
			}
		
	});
	
	$('input#searchButton').click(function(event){
			if ($('input#searchField').attr('value') == searchText || '') {
				event.preventDefault();
			}
		}
		);
		//show the page, non js get markup with different css
		$('div#container').show();
		
		//position the smaller logos
		if ($('div.ondemand').length) {
			$('div#tlagay').css('left', '400px');
			$('div#tlaraw').css('left', '200px');
		} else {
			$('div#tlagay').css('left', '400px');
			$('div#tlaraw-wrapper').css('left', '200px');
			$('div#tlacult-wrapper').css('right', '200px');
			$('div#tlamovies').css('right', '400px');
		}
		//animation & interaction timing
		fadeInLogoDelay = setTimeout('fadeInLogo('+fadeInLogoSpeed+');', curDelay); 
		curDelay+=fadeInLogoSpeed+delayBuffer;
		showLogosDelay = setTimeout(showLogos, curDelay); 
		curDelay+=delayBuffer;
		animateLogosDelay = setTimeout('animateLogos('+animateLogosSpeed+');', curDelay); 
		curDelay+=animateLogosSpeed;
		if ($('div.ondemand').length) {
			showVodDescriptDelay = setTimeout(showVodDescript, curDelay); 
		}
		hoverLogosDelay = setTimeout('hoverLogos(400,200,100,100);',curDelay); 
	});
	
	function fadeInLogo(speed){
		$('h1').css({opacity: 0.0,visibility: 'visible'}).animate({opacity: 1.0}, speed);
		$('span.shadow').show().css('visibility','visible');
	}
	
	function showLogos(){
		$('h2, h2 a').css({visibility: 'visible'});
	}
	
	function animateLogos(speed){
		if ($('div.ondemand').length) {
			$('div#tlagay').animate({left: '200'}, speed);
			$('div#tlaraw').animate({left: '400'}, speed);
		} else {
			$('div#tlagay').animate({left: '0'}, speed);
			$('div#tlaraw-wrapper').animate({left: '0'}, speed);
			$('div#tlacult-wrapper').animate({right: '0'}, speed);
			$('div#tlamovies').animate({right: '0'}, speed);
		}
	}
	
	function showVodDescript() {
		$('div.window p').fadeIn('slow');
	}
	
	function hoverLogos(selectSpeed,hoverDisplaySpeed,fanSpeed,fanFadeSpeed){
		$('div.window').hover(function(){
			$(this).stop(true).animate({top : '-220'} ,selectSpeed);
			parentID = $(this).attr('id');
			$overImage = $('div#tla div.' + parentID);
			var parentDiv = $(this);
			var portalLinks = $(this).children('p').children('a');
			$(portalLinks).css('opacity',0);
			if (!$overImage.hasClass('active')) {
				$(this).oneTime(hoverDisplaySpeed, "hoverLogo", function(){
					if (!$('div.ondemand').length) {
						$(this).children('p').fadeIn('slow');
						(function() {
							$(parentDiv).addClass('hover');
							$(parentDiv).parent().addClass('hover');
						}());
						jQuery.slowEach = function( array, interval, callback ) {
							if (!array.length) {
								return;
							}
							var i = 0;
							next();
							
							function next() {
								if (callback.call(array[i], i, array[i]) !== false) 
									if (++i < array.length) {
										setTimeout(next, interval);
									} 
							}
							return array;
						};
						jQuery.fn.slowEach = function(interval, callback){
							return jQuery.slowEach(this, interval, callback);
						};
						$(portalLinks).slowEach(fanSpeed,function() {
							$(this).animate({opacity:1},fanFadeSpeed);
						});
						
						}
					});
					$overImage.css({opacity: 0.0,visibility: 'visible'}).animate({opacity: 1.0}, selectSpeed).addClass('active');
			}
		}, function(){
			$(this).stopTime("hoverLogo");
			if (!$('div.ondemand').length) {
				$('div.window p:visible').fadeOut('slow');
				$(this).removeClass('hover');
			}
			$('div.over').animate({opacity: 0.0}, selectSpeed).removeClass('active');
			$(this).stop(true).animate({top : '-190'} ,selectSpeed);
		});
		$('div.ondemand div.window').unbind();
	}
} else {
	$('div.noscript').parent('div').show();
}
