//<![CDATA[
$(document).ready(function() {

	ONEAPI.init("232336","ru",1,"utf-8");
	
	bind_caps_checker();
	
	/**
	* Gallery opener
	*/
	$("a[rel='gallery']").click(function() {
		$(this).attr('target', '_blank');
		window.open($(this).attr('href'), "TVNET-Gallery", "status=no, toolbar=no, location=no, scrollbars=yes, menubar=no, left=50, top=10");
		return false;
	});

	$("a[rel='wallpaper']").click(function() {
		$(this).attr('target', '_blank');
		window.open($(this).attr('href'), "TVNET-Wallpaper", "status=no, toolbar=no, location=no, scrollbars=no, menubar=no, left=0, top=0, height=768, width=1024");
		return false;
	});

	/*$(".game_popup").click(function() {
		$(this).attr('target', '_blank');
		window.open($(this).attr('href'), "TVNET-Games", "status=0, location=0, scrollbars=1, menubar=0, resizable=1, width=800, height=600");
		return false;
	});*/

	$('#enlarge').click(function() {

		var currentFontSize = $('.excerpt').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize);
		var newFontSize = currentFontSizeNum*1.2;
		if(newFontSize > 1000){
			newFontSize = 14;
		}
		$('.excerpt').css('font-size', newFontSize+'px');
		$('.fullArticle').css('font-size', newFontSize+'px');

		return false;
	});

	$('#reduce').click(function() {

		var currentFontSize = $('.excerpt').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize);
		var newFontSize = currentFontSizeNum*0.8;

		$('.excerpt').css('font-size', newFontSize+'px');
		$('.fullArticle').css('font-size', newFontSize+'px');

		return false;
	});

	$('a.articleToolsShareOpener').click(function() {
		var box = $(this).next('.share_box');
		var state = box.css('display');
		if(state == 'none'){
			box.show();
		}else{
			box.hide();
		}
		return false;
	});

	$('.share_title a.close').click(function() {
		$(this).parents('.share_box').hide();
		return false;
	});

	$('#homepage').click(function() {
		if($.browser.msie){
			this.style.behavior='url(#default#homepage)';
			this.setHomePage('http://www.tvnet.lv');
			return false;
		}else{
			var open = $('#homepage_ff').css('display');
			if(open == 'none'){
				$('#homepage_ff').show();
			}else{
				$('#homepage_ff').hide();
			}
			return false;
		}
	});

	$('#inSearch').click(function() {
		$(this).removeClass('inactive');
		var current_val = $(this).val();
		var default_val = SEARCH_TXT;
		if(current_val == default_val){
			$(this).val('');
		}
	})
	.blur(function() {
		if($(this).val() == ''){
			$(this).addClass('inactive');
			$(this).val(SEARCH_TXT);
		}
	});

	$('#inSubmit').click(function() {
		if($('#inSearch').val() == SEARCH_TXT){
			$('#inSearch').val('');
		}
	});

});

function pasts_focus(txt, val, isPasw){
	
	if(txt == val){
		if(isPasw){
			var elem_plain = $('#tvn_mail_password_plain');
			var elem = $('#tvn_mail_password');
			elem_plain.hide();
			elem.show();
			elem.focus();
		}else{
			var elem = $('#tvn_mail_login');
			elem.val('');
		}
	}
		
} // END pasts_focus

function pasts_blur(txt, val, isPasw){
	
	if(val == ''){
		if(isPasw){
			var elem_plain = $('#tvn_mail_password_plain');
			var elem = $('#tvn_mail_password');
			elem_plain.show();
			elem.hide();
		}else{
			var elem = $('#tvn_mail_login');
			elem.val(txt);
		}
	}
	
} // END pasts_blur

function bind_caps_checker(){
	
	$('.syspasswd').keypress(function(e) {
	    
	    var e = e || window.event;

	    // An empty field resets the visibility.
	    if(this.value === '') {
	        $('.capsLockWarning').hide();
	        return;
	    }

	    // We need alphabetic characters to make a match.
	    var character = String.fromCharCode(e.keyCode | e.which);
	    if(character.toUpperCase() === character.toLowerCase()) {
	        return;
	    }

	    // SHIFT doesn't usually give us a lowercase character. Check for this
	    // and for when we get a lowercase character when SHIFT is enabled. 
	    if((e.shiftKey && character.toLowerCase() === character) ||
	        (!e.shiftKey && character.toUpperCase() === character)) {
	        $('.capsLockWarning').show();
	    } else {
	        $('.capsLockWarning').hide();
	    }
	});
	
} // END bind_caps_checker

function gotoHoroscope(id){

	var horoscopes = new Array();
	horoscopes[0] = 'capricorn';
	horoscopes[1] = 'merman';
	horoscopes[2] = 'fish';
	horoscopes[3] = 'ram';
	horoscopes[4] = 'bull';
	horoscopes[5] = 'twins';
	horoscopes[6] = 'crab';
	horoscopes[7] = 'lion';
	horoscopes[8] = 'virgin';
	horoscopes[9] = 'scales';
	horoscopes[10] = 'scorpion';
	horoscopes[11] = 'archer';

	window.location = '/horoscope/sign/'+horoscopes[id];
}

/* Browser check */
var $buoop = {
	vs:{i:6,f:2,o:9.25,s:2,n:9},
	l: '<?= APPNAME; ?>',
	reminder: 0
}

$buoop.ol = window.onload;
window.onload=function(){
	if ($buoop.ol) $buoop.ol();
	var e = document.createElement("script");
	e.setAttribute("type", "text/javascript");
	e.setAttribute("src", "/assets/js/browser-update.js");
	document.body.appendChild(e);
}

function getFlash(movieName)
{
	if (navigator.appName.indexOf("Microsoft") != -1) {
		 return window[movieName];
	} else {
		return document[movieName];
	}
}

function playAudio(audio_id, id)
{
	var obj = getFlash("audio_player_"+ id);
	obj.loadAudio(audio_id);
	return false;
}
//]]>
