$(document).ready(function() {
$("#ambersailLoction").fancybox({
				'width'				: '75%',
				'height'			: '75%',
				'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() == 'Užsisakyti naujienlaiskį' ) {
        $(this).val('');
    }
	}).blur(function(){
    if ( $(this).val() == "" ) {
        $(this).val('Užsisakyti naujienlaiskį');
    }
	});

$('#newsletter_submit').click(function(){
	    var user_email = $('#header_email').val();
	    var letter = $('#news').val();
	    
	    if ( validEmail(user_email) )
	    {
	    	$.post('index.php', { email: user_email, news: letter }, function data(html){
	    	$('#newsletter_submit').hide('fast');
	    		$('#newsletter').html('Ačiu už registraciją');
	    	});
	    }
	    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);
	}

});

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 slideSwitch1() 
{
    var $active = $('#slideshow1 IMG.active1');
    if ( $active.length == 0 ) $active = $('#slideshow1 IMG:last');
    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next(): $('#slideshow1 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-active1');
    $next.css({opacity: 0.0})
        .addClass('active1')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active1 last-active1');
        });
}

$(function() {
    setInterval( "slideSwitch1()", 3000 );
});

function openPage(id,cid) 
{
	$.get('../tpl/inc/list.tpl.php?page='+id+'&cid='+cid, function(data) 
			{
	  			$('.result').html(data);
			});
}
