$(function() {
	if($.browser.msie && $.browser.version < 7) {
		$(document).pngFix();
		$('body').prepend('<div id="explorerbar"><a href="#show_ie_warning"><p style="background:url(img/br/iconShield.png) 0 -2px no-repeat;padding-left:25px;">Lai uzlabotu lapas attēlošanu, Jums ir jāatjauno savs pārlūks. Spied šeit lai atjaunotu.</p></a></div>');
		$('body').prepend('<div id="show_ie_warning" class="invisible"><div style="background-color:#FFFFFF;color:#333333;width:700px;height:250px;"><p style="font-size:18px;"><b>Tu lieto novecojušu pārlūku. Atjauno to!</b></p><p>Piedāvājam Tev izvēles iespēju starp šiem jaunākiem un populārākiem pārlukiem. Visi šie pārlūki ir bezmaksas, to instalēšana ir vienkārša un ātra. Nospiediet uz pārlūka kurš Tev tīk un uzstādi to! </p><ul style="padding: 0px 0px 0px 10px; list-style-image: none; list-style-position: outside; list-style-type: none;"><li onclick="window.location = \'http://www.microsoft.com/windows/Internet-explorer/default.aspx\'" id="_li1" style="margin: 0pt 10px 10px 0pt; background: transparent url(img/br/background_browser.gif) no-repeat scroll left top;cursor: pointer; width: 120px; height: 122px;float:left;">	<div id="_ico1" style="margin: 1px auto; background: transparent url(img/br/browser_ie.gif) no-repeat scroll left top; width: 100px; height: 100px; "/><div id="_lit1" style="margin: 1px auto; color: rgb(128, 128, 128); font-size: 0.8em; height: 18px; line-height: 17px; width: 118px; text-align: center;">Internet Explorer 7+</div></li><li onclick="window.location = \'http://www.mozilla.com/firefox/\';" id="_li2" style="margin: 0pt 10px 10px 0pt; background: transparent url(img/br/background_browser.gif) no-repeat scroll left top; cursor: pointer; width: 120px; height: 122px;float:left;">	<div id="_ico2" style="margin: 1px auto; background: transparent url(img/br/browser_firefox.gif) no-repeat scroll left top; width: 100px; height: 100px;"/>	<div id="_lit2" style="margin: 1px auto; color: rgb(128, 128, 128); font-size: 0.8em; height: 18px; line-height: 17px; width: 118px; text-align: center;">Firefox 3+</div></li><li onclick="window.location = \'http://www.apple.com/safari/download/\';" id="_li3" style="margin: 0pt 10px 10px 0pt; background: transparent url(img/br/background_browser.gif) no-repeat scroll left top; cursor: pointer; width: 120px; height: 122px;float:left;">	<div id="_ico3" style="margin: 1px auto; background: transparent url(img/br/browser_safari.gif) no-repeat scroll left top; width: 100px; height: 100px;"/>	<div id="_lit3" style="margin: 1px auto; color: rgb(128, 128, 128); font-size: 0.8em; height: 18px; line-height: 17px; width: 118px; text-align: center;">Safari 3+</div></li><li onclick="window.location = \'http://www.opera.com/download/\';" id="_li4" style="margin: 0pt 10px 10px 0pt; background: transparent url(img/br/background_browser.gif) no-repeat scroll left top; cursor: pointer; width: 120px; height: 122px;float:left;">	<div id="_ico4" style="margin: 1px auto; background: transparent url(img/br/browser_opera.gif) no-repeat scroll left top; width: 100px; height: 100px; "/>	<div id="_lit4" style="margin: 1px auto; color: rgb(128, 128, 128); font-size: 0.8em; height: 18px; line-height: 17px; width: 118px; text-align: center;">Opera 9.5+</div></li><li onclick="window.location = \'http://www.google.com/chrome\';" id="_li5" style="margin: 0pt 10px 10px 0pt; background: transparent url(img/br/background_browser.gif) no-repeat scroll left top; -moz-background-clip: border; cursor: pointer; width: 120px; height: 122px;float:left;">	<div id="_ico5" style="margin: 1px auto; background: transparent url(img/br/browser_chrome.gif) no-repeat scroll left top; width: 100px; height: 100px; "/>	<div id="_lit5" style="margin: 1px auto; color: rgb(128, 128, 128); font-size: 0.8em; height: 18px; line-height: 17px; width: 118px; text-align: center;">Chrome 2.0+</div></li></ul><p style="clear:both;margin-top:12px;"><b>Ja lietojat datoru darbā, vai arī Jums nav iespējas instalēt jaunu programmatūru uz datora, sazinities ar savu IT cilvēku lai viņš veic pārlūka atjaunošanu!</b></p></div></div>');
		$("#explorerbar a").fancybox({ 'hideOnContentClick': false,'frameWidth':700,frameHeight:250 });

	}
	$('#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()
		$('.tv-channels-boxes, .channel-list').toggle()
		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) {
}

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 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
	})
}