$(function() {
	setTimeout(function(){LoadMainJs();},0);
});
var smpoplist=new Array;
var smpoplist_t=new Array;
function ShowSmallPopUrl(par,el,url,t) {
	if (!t) {
		t='l';
	}
	if($.browser.msie && $.browser.version < 7) {
		var l=Math.abs($('#'+el).width());
	} else {
		var offset = $('#'+el).position();
		if (t=='l') {
			var l=Math.round(offset.left+($('#'+el).width()));
		} else {
			var l=Math.round(offset.left-222);
		}
	}
	var tt='<div class="css_pop_up_text_box_1" id="'+el+'_popup" style="text-align:left;width:222px;height:auto;left:'+l+'px; top:0px;"><div class="css_pop_up_text_box_1_in"><div class="css_pop_up_text_box_1_in_2" id="'+el+'_popupsat"></div><div class="css_pop_up_text_box_1_top"><img src="img/top_bg_1';
	if (t=='r') {
		tt+='r';
	}
	tt+='.png" alt="" /></div></div><div class="css_pop_up_text_box_1_footer"';
	if (t=='r') {
		tt+=' style="padding-left:0;padding-right:7px;"';
	}
	tt+='><img src="img/footer_bg_1.png" alt="" /></div></div>';
if (!smpoplist[el]) {
	$.get(url, function(data) {
		$('#'+par).append(tt);
		$('#'+el+'_popupsat').html(data);
	});
} else {
	$('#'+el+'_popup').show();
}

smpoplist[el]=true;
	clearTimeout(smpoplist_t[el]);
}
function HideSmallPopUrl(el){
	smpoplist_t[el]=window.setTimeout(function() {
		$('#'+el+'_popup').hide();
	},100);
}
function LoadMainJs(){

	if($.browser.msie && $.browser.version < 7)
		$(document).pngFix()

	$('#channel-list .next a').click(function(){
		$('#channel-list .scrollcontent').scrollTo('+=300px', 300)
		return false
	})

	$('#channel-list .prev a').click(function(){
		$('#channel-list .scrollcontent').scrollTo('-=300px', 300);
		return false
	})

	$('.map-container .expander a').click(function(){
		$(this).parents('.map-container').find('.mapbox').toggle()
		$(this).find('span').toggle()
		return false
	})

	$('table.tv-guide a').click(function(){
		if (!$(this).parents('table').hasClass('expanded'))
			$(this).parents('tr').toggleClass('expanded')
		return false
	})
	$('.tv-guide .expander a, .days-menu .expander a').click(function(){
		$('table.tv-guide').toggleClass('expanded')
		$(this).find('span').toggle()
		return false
	})
	$('#player-box .playlist h2 a').click(function(){
		currentItem = $(this).parents('li')
		if(currentItem.hasClass('active'))
			return false
		$('#player-box .playlist li p').slideUp('fast')
		$('#player-box .playlist li').removeClass('active')
		currentItem.find('p').slideDown('fast')
		currentItem.addClass('active')

		video = currentItem.find('h2 a').attr('href')
		video = video.substr(1, video.length)
		createPlayer(video, true)

		return false
	})

	$('#invoice-explanation .explanations li')
		.hover(
			function(){
				$(this).addClass('active')
			},
			function(){
				$(this).removeClass('active')
			}
		)

	$('.news-navigation li.mail>a').click(function(){
		$(this).parent().toggleClass('mail-active')
		$('.news-navigation li.mail .send-friend-form').toggle('blind','',150)
		$('#friends_email').focus()
		return false
	})

	//addTabs()
	addTabsBySelector('#text')
	//addTabsBySelector('#faq')
	//addTabsBySelector('#free-channels')

	$('#faq h5 a').click(function(){
		if ($(this).parents('li').hasClass('active'))
			return false
		$('#faq h5').parents('li.active').find('p').hide('blind','',100).end().removeClass('active')
		$(this).parents('li').find('p').show('blind','',100).end().addClass('active')
		return false
	})

	$('#highlights-box li').click(function(){
		if($(this).hasClass('active')) {
			window.location = $('#highlights-box li.active a').attr('href');
			return false
		}
		$('#highlights-box li.active').removeClass('active')

		$(this).addClass('active')


		$('#highlights-box .big').scrollTo($('#highlights-box .item-big').eq($('#highlights-box li').index(this)), 200)


		return false
	})

	$('#tv-guide .channels-genres a').click(function(){
		if($(this).hasClass('active'))
			return false
		$('#tv-guide .channels-genres a.active').removeClass('active')
		$(this).addClass('active')
		$('#channel-list .scrollcontent').scrollTo($(this).attr('href'), 300)
		return false
	})

	$('.service-availability .picture a, .box-local-dealer .picture a').fancybox({
		frameWidth: 783,
		frameHeight: 490,
		padding: 0
	})

	//createFrontPagePlayer('ViasatPlusHDpauseandrewLATNEWDISCL', false)

	//frontpagePlayerListScroll()

	$('#text #tv-channels .tv-channels-full-menu .full a').click(function(){
		$(this).parent().find('a').toggle()
		//$(this).parent('.tv-channels-boxes, .channel-list').toggle()
		//$('.tv-channels-boxes, .channel-list').toggle()
	if ($('.tv-channels-boxes').css('display')=='none') {
	    $('.tv-channels-boxes').css('display','block');
	} else {
	    $('.tv-channels-boxes').css('display','none');
	}
	if ($('.channel-list').css('display')=='none') {
	    $('.channel-list').css('display','block');
	} else {
	    $('.channel-list').css('display','none');
	}
		return false
	})

	$('.navigation-channel-list .next a').click(function(){
		$(this).parents('.navigation-channel-list').find('.scrollcontent').scrollTo({top: 0, left: '+=200px'}, 300);
		return false
	})

	$('.navigation-channel-list .prev a').click(function(){
		$(this).parents('.navigation-channel-list').find('.scrollcontent').scrollTo({top: 0, left: '-=200px'}, 300);
		return false
	})

	$('.genre-channel-box .channels a').click(function(){
		genrebox = $(this).parents('.genre-channel-box')

		thisIndex = genrebox.find('li').index($(this).parent())

		genrebox.find('.description').scrollTo(genrebox.find('.description li').eq(thisIndex), 200);
		return false
	})

	tvchannelstabs();
}

function createPlayer(video, start) {
	$('#player-sport').flash({
		swf: 'swf/player.swf',
		width: 268,
		height: 221,
		flashvars: {
			file: '../flv/' + video + '.flv',
			wmode: 'transparent',
			image: 'flv/' + video + '.jpg',
			autostart: start
		}
	})
}

function addTabs() {
	$('.tabs li a').click(function(){
		if($(this).parent().hasClass('active'))
			return false
		$(this).parents('.tabs').find('li.active').removeClass('active')
		$(this).parents('div').eq(0).find('.tab-content').hide()
		$($(this).attr('href')).show()
		$(this).parent().addClass('active')
		return false
	})
}

function addTabsBySelector(selector) {
	$(selector + ' .tabs li a').click(function(){
		if($(this).parent().hasClass('active'))
			return false
		$(selector + ' .tabs li.active').removeClass('active')
		$(selector + ' .tab-content').hide()
		$($(this).attr('href')).show()
		$(this).parent().addClass('active')
		return false
	})
}

function upcomingHighlights() {
	$('#highlights ul').css('width', $('#highlights li').length * 183)
	$('#highlights .next a').click(function(){
		$('#highlights .scrollcontent').scrollTo('+=549px', 300)
		return false
	})
	$('#highlights .prev a').click(function(){
		$('#highlights .scrollcontent').scrollTo('-=549px', 300)
		return false
	})
}

function createFrontPagePlayer(video, start) {
	$('#frontpage-player').flash({
		swf: 'swf/player.swf',
		width: 307,
		height: 205,
		flashvars: {
			file: '../flv/'+ video +'.flv',
			wmode: 'transparent',
			image: 'flv/'+ video +'.jpg',
			autostart: start,
			skin: 'swf/modieus.swf',
			stretching: 'fill'
		}
	})
}

function frontpagePlayerListScroll() {
	var listHeight = 0

	$('#frontpage-player-list li').each(function(i){
		listHeight += $(this).height() + 6 + 11
	})

	if ($('#frontpage-player-list ul').height() > $('#frontpage-player-list').height())
	{
		$('#frontpage-player-list .slider').show()
	}

	$('#frontpage-player-list .down').click(function(){
		$('#frontpage-player-list ul').scrollTo('+=62px', 150)
		sliderValue = $("#frontpage-player-list .body").slider('option', 'value')

		if (listHeight * sliderValue * 10 /100 - 62 < 70)
			$("#frontpage-player-list .body").slider('option', 'value', 0)
		else
			$("#frontpage-player-list .body").slider('option', 'value', Math.round(10 * (listHeight * sliderValue * 10 /100 - 62) / listHeight))
		return false
	})
	$('#frontpage-player-list .up').click(function(){
		$('#frontpage-player-list ul').scrollTo('-=62px', 150)
		sliderValue = $("#frontpage-player-list .body").slider('option', 'value')
		if (sliderValue < 1)
			$("#frontpage-player-list .body").slider('option', 'value', Math.round(10 * (listHeight - 62) / listHeight))

		else
		{
			if (listHeight * sliderValue * 10 /100 < 70)
				$("#frontpage-player-list .body").slider('option', 'value', 10)
			else
				$("#frontpage-player-list .body").slider('option', 'value', Math.round(10 * (listHeight * sliderValue * 10 /100 + 62) / listHeight))
		}

		return false
	})

	$("#frontpage-player-list .body").slider({
		orientation: "vertical",
		range: "min",
		min: 0,
		max: 10,
		value: 10,
		slide: function(event, ui) {
			$('#frontpage-player-list ul').scrollTo(100 - ui.value * 10 + '%', 0)
		}
	})

	$('#frontpage-player-list li a').click(function(){
		video = $(this).attr('href')
		video = video.substr(1, video.length)

		createFrontPagePlayer(video, true)

		return false
	})
}
function tvchannelstabs() {
	$('.package-menu a').click(function(){
		if($(this).parent().hasClass('active'))
			return false

		$(this).parents('ul').find('li').toggleClass('active')

		$('.p_gold, .p_start').toggle()

		return false
	})
}