$(document).ready(function() {
	// IE6 checker
	if ($.browser.msie && $.browser.version == '6.0' && location.href.indexOf('notallowed') != -1) {
		$('body')
			.empty()
			.append('\
					<style type="text/css">\
						div { width:960px;height:200px;margin:10px auto;background:#FFF;text-align:center; }\
						p { font-size:24px;color:#333;font-weigh:bold; }\
					</style>\
					<div>\
						<p style="margin-top:65px;">Sorry, this website is not compatible with your web browser.</p>\
						<p>We recommand you to install Internet Explorer 8+ or Mozilla Firefox 3+.</p>\
					</div>\
			')
	}

	// Form unfiller
	$('input[type=text]')
		.focusin(function () {
			var self = $(this), v = self.val()
			if (v != '') self.data('initialContent', v).val('')
		})
		.focusout(function () {
			var self = $(this), v = self.val()
			if (v == '') self.val(self.data('initialContent'))
		})

	// Header menu
		$('#menu-item-121').mouseenter(function () {showBlindTopMenu($('.menu-television-container'))});
		$('#menu-item-122').mouseenter(function () {showBlindTopMenu($('.menu-tmc-regie-container'))});
		$('#menu-item-119').mouseenter(function () {showBlindTopMenu($('.menu-digital-container'))});
		
		$('#header').mouseleave( function() { if ($('.menu2-header').is(':visible')) $('.menu2-header').stop(true, true).hide('blind').find('a').hide() });
})

function showBlindTopMenu(menuItem) {
	var menu = $('.menu2-header')
	if (menu.is(':visible') && menuItem.find('a:first').is(':visible')) return false

	var delay = 0
	if (menu.is(':hidden')) {
		menu.show('blind')
		delay = 150
	}

	menu.children('div').hide()
	menu.find('a').each(function () {
		clearTimeout($(this).data('to'))
		$(this).stop(true, true).hide()
	})
	menuItem.show()
	menuItem.find('a').each(function (index) {
		var self = $(this)
		self.data('to', setTimeout(function () {self.fadeIn()}, delay + 150 * index))
	})
}

function blankLink(link) {
	window.open(link, '_blank');
	return false;
}

function toggleSubmenu(self) {
	var menu = self.closest('li').children('#rollmenu');
	var classe = $('#submenu-2').attr('class');
	
	if (menu.is(':hidden')) {
		
		if(classe  =='tmc')
		{
			if (self.css('color') != '#ECECEE') {
				self.css({color:'#00abc4'});
				self.data('colorSwitch', 1);
			}
		}
		if(classe  =='nt1')
		{
			self.css({color:'#FFFFFF'});
			self.data('colorSwitch', 1)	;
		}
		
		menu.show('blind','fast', function(){ show_item(); });
		
	} else {
			var data = self.data('colorSwitch');
		
			if( data == 1 ){		
				self.css({color:''});
			}
		
			$('.roll-link').each( function(){ $(this).hide(); });
			menu.hide('blind');
	}
	
	return false;
}

function show_item()
{
	var i=0;
		$('.roll-link').each( function (){
			
			if ($.browser.msie && $.browser.version == '8.0') {
				$(this).delay(150*i).fadeIn('slow');
			}else
			{
				//$(this).delay(150*i).fadeTo('normal', 1, function() {$(this).css('display:inline'); });
				$(this).delay(150*i).show('fade', 'slow');
			}
			
			i++;
			
		});
}



function showLb(self) {
	var lb = self.parent().children('.lightbox')

	if (lb[0])	lb.detach().prependTo($('#content')).fadeIn()
	else		$('.'+self.attr('id')).fadeIn()
}

function hideLb(self) {
	self.closest('.lightbox').fadeOut()
}

function accordionToggle(self) {
	var selfContent = self.closest('li').children('.sponso-content')
	
	if (selfContent[0] && selfContent.is(':hidden')) {
		var selfLink = self.closest('li').children('input[name=pdf]').val()
		var selfVideo = self.closest('li').children('input[name=flv]').val()

		$('.sponso-content:visible').toggle('slow')
		selfContent.toggle('slow')

		$('.sponso-title').css({borderBottom:'none'})
		self.css({borderBottom:'1px dotted #00adc6'})
		
		$('#sponso-link').attr('href', selfLink)
		document.getElementById("TmcRegie").joueUneVideo(selfVideo)
		$('.currentVideo').removeClass('currentVideo')
		self.closest('li').addClass('currentVideo')
	} else return false;
}

function finVideo() {
	var currentVideo = $('.currentVideo'),
		videoType = (currentVideo.hasClass('tmc-video')?'TMC':'NT1'),
		i = currentVideo.attr('id').substr(11)
	
	setTimeout(function () {accordionToggle(videoType=='TMC'?$('#sponso-nt1-'+i):$('#sponso-tmc-'+(i+1)));}, 1000)
}

function toggleFaq(self) {
	var answer = $('.answer.'+self.attr('id'))
	if (answer.is(':hidden')) {
		$('.answer:visible').slideUp()
		answer.slideDown()
	}
	return false
}
