var player_array = {};

/**
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne <brian@cherne.net>
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);
 function settemplate(tmpl){
	if(tmpl=='placiau')
		$("#tpl").val('2');
	else
		$("#tpl").val('3');
	input = 0;
	$("input[type='checkbox']:checked").each( 
			function() { 
				input=input+1;
		});
	if(input>0)
		$('#m8c8d5moduleform_1').submit();
	else
		alert('Nepasirinkote nei vieno mokymo!')
 }

(function($){
 $.fn.extend({
 
     customStyle : function(options) {
      if(!$.browser.msie || ($.browser.msie&&$.browser.version>6)){
      return this.each(function() {
      
            var currentSelected = $(this).find(':selected');
            $(this).after('<span class="'+options.outer+'"><span class="'+options.inner+'" id="a_'+$(this).attr('id')+'">'+currentSelected.text().substr(0,options.len)+'</span></span>').css({position:'absolute', opacity:0,  fontSize:$(this).next().css('font-size')});
            var selectBoxSpan = $(this).next();
            var selectBoxWidth = parseInt($(this).width()) - parseInt(selectBoxSpan.css('padding-left')) -parseInt(selectBoxSpan.css('padding-right'));            			
			
            var selectBoxSpanInner = selectBoxSpan.find(':first-child');
            selectBoxSpan.css({display:'inline-block'});
			
			if (options.dw == 1)
				selectBoxSpanInner.css({width:selectBoxWidth, display:'inline-block'});
			else			
				selectBoxSpanInner.css({display:'inline-block'});
			
            var selectBoxHeight = parseInt(selectBoxSpan.height()) + parseInt(selectBoxSpan.css('padding-top')) + parseInt(selectBoxSpan.css('padding-bottom'));
            $(this).height(selectBoxHeight).change(function(){
                selectBoxSpanInner.text($("#"+$(this).attr('id')+" :selected").text().substr(0,options.len)).parent().addClass('changed');
                
            });
            
      });
      }
    }
 });
})(jQuery); 

$(document).ready(function(){

	
$("a[href^='\#']").click(function(e){
  e.preventDefault();
  document.location.hash=this.href.substr(this.href.indexOf('#')+1);
});

 var url=location.href; 
       var istag= url.split('#');
       var aktyv=istag[1];
       if (aktyv!=undefined && aktyv!="" ){    
        var scrl = $("#mok_"+aktyv).offset().top-120;
        $('html,body').animate({scrollTop: scrl}, 800);
       }   


$('select.selectf, select.cms_dropdown').customStyle({outer: 'select_f', inner: 'select_fInner', len: '200'});

	/*$('.subm').mouseenter(function(){
    
        var subm = $(this).parent().find('.submenu').show();
        var width=$(this).parent().width();
        var off = subm.offset();
        subm.css("top","142px");
		var position1 = $(subm).offset();
		var position2 = $(this).parent().offset();
		
        $('.submenu').width(width);
        if (position1.left != position2.left) {$('.submenu').css('margin-left', '-'+width+'px');}
        
    });*/
    
	
	//////////Orandzinio issiskleidimas/////////////
    $('.extreem').mouseleave(function(e){
        $(this).find('.submenu').hide();
    });

    $('.extreem').mouseenter(function(){    
        $(this).find('.submenu').show();
    });

	
	
	///////////Suskaiciuojam popup'u koordites//////////////////
	/*$('.popuparea').parent().each(function() { //li
	
		var subm = $(this).children('.popup'); // pasizymim submeniu
        var width = $(this).width(); //linko ilgis
        var off = $(this).parent().position().left; //meniu pradzios koordinates
		var off2 = $(this).position().left; //li koordinates
		var poslinkis = 21; // popup'o poslinkis nuo meniu pabaigos
		var meniuilgis = $(this).parent().width(); //meniu bendras ilgis
		var konstanta = 103;
		
		var atitraukimas;
		var topatitraukimas;
		
		if ( $.browser.msie ) {
			atitraukimas = 342+(width/2); topatitraukimas = 89;
		} else {
			atitraukimas = 342-(width/2);
			topatitraukimas = 83;
		}
		
		if (off2 > 580) { //jei linko pozicija per arti krasto
			var skirtumas = off2-off-342;
			//var atitraukti = 330+skirtumas+(width/2)+poslinkis;
			var popkoord = off+meniuilgis-684+poslinkis;
			var constanta = off-popkoord-342;
			var atitraukti = 330+(off2-off)+(width/2)+poslinkis+constanta-10;
			$(this).children().children('.rodykl').css("margin-left", atitraukti+"px");
			subm.css("left", popkoord+"px");
		} else { //nustatom normaliai
			subm.css("margin-left", "-"+atitraukimas+"px");
		}
		subm.css("top", topatitraukimas+"px");
	});*/
	
	
	/*$('.popuparea').parent().click(function(){
		//console.log($(this).children('.popup'));
		$('.popuparea').parent().parent().each(function() {
			$(this).find('.popup').hide();
		});
        $(this).children('.popup').show();
    });*/
	
	/////////////Slepiam rodom popup'a/////////////////
	$("body").click(function(e){
		var artimiausias1 = $(e.target).closest($('.popup1').parent());
		var artimiausias2 = $(e.target).closest($('.popup2').parent());
		if(artimiausias1.size() == 0) {
			$('.topmenu .aktyvi').hide();
		}
		if(artimiausias2.size() == 0) {
			$('.menu .aktyvi').hide();
		}
	});
	
	$('.popuparea').click(function(e){
        var kaz = $(this).parent().find('.popup');
		if (kaz.css('display') == 'block') {	
			kaz.hide();
			kaz.removeClass('aktyvi');
		} else {
			$(this).parent().parent().find('.popup:visible').hide();
			kaz.show();
			kaz.addClass('aktyvi');
		}
    });
	
	
	
	
	

	
	
	
	
	/////////////Hover background/////////////////
	$('#header .menu td.c1').mouseleave(function(e){
        if ($('#header .menu td.extreem').hasClass('active')) {
			$('#maina').css('background', 'url(images/mainbg01.png) no-repeat top center #f7f9f7');
		} else { 
			if ($(this).hasClass('ac')) {
				$('#maina').css('background', 'url(images/mainbg10.png) no-repeat top center #f7f9f7');
			} else {
				$('#maina').css('background', 'url(images/mainbg.png) no-repeat top center #f7f9f7');
			}
		}
    });
	$('#header .menu td.c1').mouseenter(function(){
	
        if ($('#header .menu td.extreem').hasClass('active')) {
			$('#maina').css('background', 'url(images/mainbg11.png) no-repeat top center #f7f9f7');
		} else {
			$('#maina').css('background', 'url(images/mainbg10.png) no-repeat top center #f7f9f7');
		}
    });
	$('#header .menu td.extreem').mouseleave(function(e){

        if ($('#header .menu').find('td.ac').hasClass('c1')) {
			$('#maina').css('background', 'url(images/mainbg10.png) no-repeat top center #f7f9f7');
		} 
		else if ($('#header .menu').find('td.ac').hasClass('extreme')){
			$('#maina').css('background', 'url(images/mainbg01.png) no-repeat top center #f7f9f7');
		}
		else {
			$('#maina').css('background', 'url(images/mainbg.png) no-repeat top center #f7f9f7');
		}
    });
	$('#header .menu td.extreem').mouseenter(function(){
			$('#maina').css('background', 'url(images/mainbg01.png) no-repeat top center #f7f9f7');
			
    });
	$('#header .menu td.extreem a').mouseenter(function(){
			$("#header .menu td").removeClass('active');
    });
	
		$('#header .menu .submenu td a').mouseenter(function(){
			$("#header .menu td").removeClass('active');
    });
	$('#header .menu td.extreem .submenu a').mouseleave(function(){
			$("#header .menu ").removeClass('active');
    });
	///////OnPageLoad nustatom backgrounda/////////////////////
	if ($('#header .menu td.extreem').hasClass('active')) {
		if ($('#header .menu td.c1').hasClass('active')) {
			$('#maina').css('background', 'url(images/mainbg11.png) no-repeat top center #f7f9f7');
		} else {
			$('#maina').css('background', 'url(images/mainbg01.png) no-repeat top center #f7f9f7');
		}
	} else {
		if ($('#header .menu td.c1').hasClass('active')) {
			$('#maina').css('background', 'url(images/mainbg10.png) no-repeat top center #f7f9f7');
		}
	}
	
	
	
	///////////Oranzinio issiskleidimo koordinates/////////////
	var ilg = $('body').width(); //puslapio ilgis
	if ( $.browser.msie ) {ilg = ilg-21;}
	
	var prasideda = $('#header').position().left; //puslapio pradzios koordinate
	var nuovirsaus = $('.submenu').position().top+158;
	var konstanta = 80;
	
	if (ilg > 1150) { // fiktuotoj vietoj
		$('.submenu').css('left', (ilg-1150)/2)+'px';
		$('.submenu').css('width', '1151px');
		$('.submenu td.free').css('width', konstanta+'px');
	} else { // prie krasto
		$('.submenu').css('left', '0px');
		$('.submenu').css('width', ilg+'px');
		if (ilg > 990) {
			$('.submenu td.free').css('width', ((ilg-990)/2)+'px');
		}
	}
	//console.log(nuovirsaus);
	$('.submenu').css('top', nuovirsaus+'px');
	
	
	
	////////////Pagr. meniu hoveris////////////////////
	$("#header .mainmenu table td").hover(function (e) {
	
		if ($(this).hasClass('extreem')) {
			$(this).addClass("hover2");
			$("#header .menu td").removeClass('active');
			$('#maina').css('background', 'url(images/mainbg01.png) no-repeat top center #f7f9f7');
		} else {
			$(this).addClass("hover");
			$("#header .menu td").removeClass('active');
			if($(this).hasClass('c1')){
				$('#maina').css('background', 'url(images/mainbg10.png) no-repeat top center #f7f9f7');
			}
			else if($(this).find('td.ac').hasClass('extreem')){
				$('#maina').css('background', 'url(images/mainbg01.png) no-repeat top center #f7f9f7');
			}
			else{
			if($("#header .menu td .submenu").is(':visible')){
				$('#maina').css('background', 'url(images/mainbg01.png) no-repeat top center #f7f9f7');
			}
			else
				$('#maina').css('background', 'url(images/mainbg.png) no-repeat top center #f7f9f7');
				}
		}
		
		
	}, function () {
		if ($(this).hasClass('extreem')) { 
			$(this).removeClass("hover2");
		} else {
			$(this).removeClass("hover");
			if($("#header .menu").find('td.ac').hasClass('extreem'))
				$('#maina').css('background', 'url(images/mainbg01.png) no-repeat top center #f7f9f7');
			if($("#header .menu").find('td.ac').hasClass('c1')){
			if($("#header .menu td .submenu").is(':visible')){
				$('#maina').css('background', 'url(images/mainbg01.png) no-repeat top center #f7f9f7');
			}
			else
				$('#maina').css('background', 'url(images/mainbg10.png) no-repeat top center #f7f9f7');
			}
			
		}
		if($("#header .menu td .submenu").is(':visible')){
			$("#header .menu td").removeClass('active');
		}
		else{
			$("#header .menu").find('.ac').addClass('active');
		}
	});

	
	$("#slider2").easySlider({
		vertical: true,
		nextId: "next2",
		prevId: "prev2"
	});
	
	
	$('#slides').slides({
		preload: false,
		generateNextPrev: false,
		generatePagination: false
	});
	
	$('#pranesimai').slides({
		preload: false,
		generateNextPrev: false,
		generatePagination: false
	});
	
	
	
	$("#content .general .infoblock tr:even").addClass("even");
	$("#content .general .infoblock table.beremeliu tr:even").removeClass("even");
	
	
	
	
	
	
	function megaHoverOver(){
	
		var sub = $(this).find(".popup");
		//$(this).find("span").addClass("active");
		//$(this).find("a").addClass("active");
		var parent = $(".menu");
		var p = parent.offset();
		var s = $(this).offset();
		//Top sub
		var height = parseInt(p.top)+parseInt(parent.outerHeight());
		if (parseInt($(this).offset().top) < 100) {height = parseInt($(this).offset().top)+20}
		else {height = 161;}
		
		var windows_h =  parseInt($(window).width());
		//sub.show();
		var sub_w = parseInt(sub.outerWidth());
		//sub.hide();
		// 7 seslio plotis
		var widths=$(this).width();
		var left = parseInt(s.left) - 342 + (widths/2);
		if (left < 0) {
			var atitraukti = 330+left;
			sub.children('.rodykl').css("margin-left", atitraukti+"px");
			left = 0;
			
		}
		//Tikrinama ar sub neiseina uz lango ribu
		if ((left+sub_w)>=windows_h) {
			left = left-((left+sub_w)-windows_h);
			
			//console.log(windows_h-$(this).position().left, left);
			//var delta = $(this).offset().left - $(this).closest($('.popupmenu')).width();
			var delta = $(this).position().left-windows_h;
			//console.log(delta);
			//if (delta > 0) 
			{
				var atitraukti = 330+delta+342+(widths/2)+7;
				sub.children('.rodykl').css("margin-left", atitraukti+"px");
			}
		}
		
		var off = $(this).parent().position().left; //meniu pradzios koordinates
		var off2 = $(this).position().left; //li koordinates
		
		sub.css({
				'top':height+'px',
				'left':left+'px'		
		});
		//$(this).children('.rodykl').css("margin-left", atitraukti+"px");
		//var atitraukti = 330+(off2-off)+(width/2)+poslinkis+constanta-10;
		
		//sub.show();
		var skaicius = parseInt(sub.find("ul").size());
		//sub.hide();
		if (skaicius>0){;	
				//sub.stop().show();
			};
			

		
	}
	
	function megaHoverOut(){ 
	  
	  //$(this).find(".popup").hide();
	  //$(this).find("span").removeClass("active");
	  //$(this).find("a").removeClass("active");

	}

 
	var config = {    
		 sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)    
		 interval: 0, // number = milliseconds for onMouseOver polling interval    
		 over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    
		 timeout: 0, // number = milliseconds delay before onMouseOut    
		 out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
	};
 
	$("table.menu td").hoverIntent(config);
	$(".topmenu li").hoverIntent(config);
 
 	$(".animate_video2").click(function(e){
		if($('.video-close').size()>0){
			$.each($('.video-close'), function(index, value){
				close_video($(value));
			});
		}
		var params = {'width':'280px','height':'163px'};
		var params1 = {'width':'270px'}
		$(this).animate(params, 'slow');
		$(this).find('img').animate(params, 'slow');
		$(this).closest('.patarimai').find('.ekspertai').animate(params1, 'slow');
		$(this).closest('.patarimai').find('.foto').css('float','none');
		var a_element = $(this).closest('.patarimai').prepend('<a class="video-close" title="Close video">x</a>');
		return false;	
	})	
	
	$('#slid').delegate('.video-close','click',function(){
		close_video($(this))
	});
});

function close_video(obj){
	$f().unload();
	var params = {'width':'109px','height':'112px'};
	var params1 = {'width':'160px'};
	obj.closest('.patarimai').find('.foto').animate(params, 'slow');
	obj.closest('.patarimai').find('.foto > a, .foto > a > img').animate(params, 'slow');
	obj.closest('.patarimai').find('.ekspertai').animate(params1,'slow');
	obj.closest('.patarimai').find('.foto').css('float','left');
	obj.remove();
}


function start_video(id){
		obj = $("#"+id);
		if($('.video-close').size()>0){
			$.each($('.video-close'), function(index, value){
				close_video($(value));
			});
		}
		var params = {'width':'280px','height':'163px'};
		var params1 = {'width':'270px'}
		obj.animate(params, 'slow');
		obj.find('img').animate(params, 'slow');
		obj.closest('.patarimai').find('.ekspertai').animate(params1, 'slow');
		obj.closest('.patarimai').find('.foto').css('float','none');
		obj.closest('.patarimai').prepend('<a class="video-close" title="Close video">x</a>');
		
}


