$(document).ready(function() {
	$('#searchSchBtn').click(function() {
		$('#chanChild').val($('#chanMain').val());
		if($('#txtTitle').val() == '') {
			//alert('type ');
			return false;
		}
	});
	
	
	function addMenu() {
		$('a.menu img', this).attr('src', '/images/menu/'+$(this).attr('id')+'-hover.png');
		$('ul', this).slideDown();
	}
	
	function removeMenu() {
		$('a.menu img', this).attr('src', '/images/menu/'+$(this).attr('id')+'.png');
		$('ul', this).slideUp();
	}
	
	var menuConfig = {
		interval: 30,
		sensitivity: 4,
		over: addMenu,
		timeout: 200,
		out: removeMenu
	};
	
	$('#menu ul.list-menu li').hoverIntent(menuConfig);
	$('#menu ul.list-menu li ul.sub-menu li').hover(
		function() {
			$('a.submenu img', this).attr('src', '/images/menu/'+$(this).attr('id')+'-hover.png');
		}, function() {
			$('a.submenu img', this).attr('src', '/images/menu/'+$(this).attr('id')+'.png');
		}
	);
	
	$('a[href*=#]').click(function() {
		var duration=1000; // duration in ms
		var easing='swing'; // easing values: swing | linear
		var newHash=this.hash; // get / set parameters
		var target=$(this.hash).offset().top;
		var oldLocation=window.location.href.replace(window.location.hash, '');
		var newLocation=this;
		
		if(oldLocation+newHash==newLocation) { // make sure it's the same location
			$('html:not(:animated),body:not(:animated)').animate({ scrollTop: target }, duration, easing, function() { // animate to target and set the hash to the window.location after the animation
				window.location.href=newLocation; // add new hash to the browser location
			});
			
			return false; // cancel default click action
		}
	});
	
	$('#promo-banner-nav-start a').click(function() { $(this).slideUp(200); $('#promo-banner-nav').slideDown(); });
	$('#header').cycle({ fx: 'fade', timeout: 5000 });
	// $('#promo-banner-img').mouseover(function() { $('#promo-banner-nav').show(); }).mouseout(function() { $('#promo-banner-nav').hide(); });
	$('#promo-banner-img').cycle({ fx: 'scrollHorz', timeout: 3000, pager: '#promo-banner-nav', pagerAnchorBuilder: pagerFactory });
	$('#promo-banner-img-mini').cycle({ fx: 'scrollHorz', timeout: 3000, pager: '#promo-banner-nav', pagerAnchorBuilder: pagerFactory });
	
	function pagerFactory(idx, slide) {
		// var s = idx > 2 ? ' style="display:none"' : '';
		var s = idx;
		return '<li class="'+s+'"><a href="#">'+(idx+1)+'</a></li>';
	};
	
	checkBrowsah();
	flashPlayerDetection();
});

function toSchedule(mod, channel_id, date) {
	window.location = 'index.php?mod='+mod+'&channel='+channel_id+'&date='+date;
}

function checkBrowsah() {
	if ($.browser.msie) {
		if (parseInt($.browser.version) == 6) {
			$('#highone').css('padding', '8px 8px 0px 8px');
			// $('#right').css('padding', '8px 6px 8px 0');
			$('#promo-head').css('width', '245px');
			$('#fcright').children().children().attr('src', 'images/global.jpg');
		} else if (parseInt($.browser.version) == 7) {
			$('#highone').css('padding', '8px 8px 0px 8px');
		}
	}
}

function flashPlayerDetection() {
	// var DLFP = '<a href="http://get.adobe.com/flashplayer/" target="_blank">please download flash player 9 or above</a>';
	var DLFP = '<a href="http://get.adobe.com/flashplayer/" target="_blank">this banner requires flash player 9.0 or later</a>';
	
	if (!FlashDetect.installed) {
		// alert("Flash is required to enjoy this site.");
		$('#highone-img').html('<br /><br /><br /><br /><br /><br /><br /><br /><br />'+DLFP);
		$('#vstreamContent').html('<br /><br /><br /><br /><br /><br /><br />'+DLFP);
	} else {
		if (!FlashDetect.versionAtLeast(9)) {
			// alert("Flash Player 9 or greater is installed");
			$('#highone-img').html('<br /><br /><br /><br /><br /><br /><br /><br /><br />'+DLFP);
			$('#vstreamContent').html('<br /><br /><br /><br /><br /><br /><br />'+DLFP);
		}
	}
}
