$(document).ready(function() {
$("#loial").fancybox({
				'width'				: '75%',
				'height'			: '85%',
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
			});
$("#career").fancybox({
	'width'				: '75%',
	'height'			: '85%',
	'autoScale'			: false,
	'transitionIn'		: 'none',
	'transitionOut'		: 'none',
	'type'				: 'iframe'
});

$("#form").fancybox({
	'width'				: '75%',
	'height'			: '85%',
	'autoScale'			: false,
	'transitionIn'		: 'none',
	'transitionOut'		: 'none',
	'type'				: 'iframe'
});

$("a[rel=img_group]").fancybox({
	'transitionIn'		: 'none',
	'transitionOut'		: 'none',
	'titlePosition' 	: 'over',
	'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
		return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
	}
	});

$("a[rel=fla_group]").fancybox({
	'transitionIn'		: 'none',
	'transitionOut'		: 'none',
	'type'				: 'iframe',
	'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
		return '<span id="fancybox-title-over">Video ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
	}
	});

$('#header_email').focus(function()
		{
    		if ($(this).val() == ml)
    		{
    			$(this).val('');
    		}
		}).blur(function(){
			if ( $(this).val() == "" ) 
			{
				$(this).val(ml);
			}
	});

$('#comment').focus(function()
		{
    		if ($(this).val() == tx)
    		{
    			$(this).val('');
    		}
		}).blur(function(){
			if ( $(this).val() == "" ) 
			{
				$(this).val(tx);
			}
	});

$('#newsletter_submit').click(function(){
	    var user_email = $('#header_email').val();
	    var letter = $('#news').val();
	    var comment = $('#comment').val();
	    
	    if ( validEmail(user_email))
	    {
	    	$.post('/', { email: user_email, news: letter, comment: comment }, function data(html){
	    		$('#err').html('Ačiu už žinutę');
	    	});
	    }
	    else 
	    {
	        $('#err').html('Neteisingas elektroninis paštas');
	    }
	});


function validEmail(elementValue){
	var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
	return emailPattern.test(elementValue);
	}

$('#lire').click(function () {
	if ($("#contBody").is(":hidden")) {
	$("#contBody").slideDown("slow");
	$("#lire").text(cl);
	} else {
		$("#contBody").slideUp("slow");
		$("#lire").text(rd);
	}
	});


$(".m1").mouseover(function(){
    $(this).stop().animate({marginLeft: "0px"}, 100);
    $(".m2").stop().animate({marginLeft: "140px"}, 100);
    $(".m3").stop().animate({marginLeft: "320px"}, 100);
    });
    $(".m1").mouseout(function(){
    $(this).stop().animate({marginLeft: "-140px"}, 100);
    $(".m2").stop().animate({marginLeft: "20px"}, 100);
    $(".m3").stop().animate({marginLeft: "140px"}, 100);
    });
    $(".m2").mouseover(function(){
    $(this).stop().animate({marginLeft: "131px" }, 100);
    $(".m3").stop().animate({marginLeft: "262px"}, 100);
    });
    $(".m2").mouseout(function(){
    $(this).stop().animate({marginLeft: "0px"}, 100);
    $(".m3").stop().animate({marginLeft: "131px"}, 100);
    });
    $(".m3").mouseover(function(){
    $(this).stop().animate({marginLeft: "262px"}, 100);
    });
    $(".m3").mouseout(function(){
    $(this).stop().animate({marginLeft: "131px"}, 100);
    });
    $(".m5").mouseover(function(){
    //$(this).stop().animate({width: "264px" }, 100);
    $(".m4").stop().animate({width: "131px"}, 100);
    });
  //  $(".m5").mouseout(function(){
   // $(this).stop().animate({width: "264"}, 100);
    //});
$("#slidemenu").mouseout(function(){
    $(".m4").stop().animate({width: "264px"}, 100);
    });

});



function slideSwitch() 
{
    var $active = $('#slideshow IMG.active');
    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');
    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next(): $('#slideshow IMG:first');
    // uncomment the 3 lines below to pull the images in random order
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );
    $active.addClass('last-active');
    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "slideSwitch()", 5000 );
});

function openPage(id,cid) 
{
	$.get('../tpl/inc/list.tpl.php?page='+id+'&cid='+cid, function(data) 
			{
	  			$('.result').html(data);
			});
}
