/**
 * OWcms
 *
 * @author              Outside World Studio
 * @copyright           (c) 2010 Outside World Studio || owstudio.com
 * @link                http://owstudio.com/
 * @version             0.1 alpha
 */
 
jQuery(document).ready(function() {
    slideShow(4000);

    $('.gallery_list_photo a').lightBox();

    $('#newsletter_request').submit(function() {
        $.post($('#newsletter_request').attr('action'), { newsletter_submit : $('#newsletter_submit').val(), newsletter_email : $('#newsletter_email').val(), espole : $('#e-s-pole').val(), eshpole : ( $('#e-s-h-pole').val() == '' || $('#e-s-h-pole').val() === undefined ? '' : $('#e-s-h-pole').val() ) }, function(data) {
          
                $('#newsletter_hint').fadeIn('fast', function(){
                    $('#newsletter_hint').css('display', 'block');
                    $('#newsletter_hint').html(data);
                });
        });

        return false;
    });
});

var anim = 0;
var timer;
var global_speed = 0;

function slideShow(speed) {
    global_speed = speed;

    $('ul.slideshow li').css({opacity: 0.0});
    $('ul.slideshow li:first').css({opacity: 1.0});

    timer = setInterval('gallery()',speed);

    $('ul.slideshow').hover(
        function () {
            if ( anim < 2 ) {
                clearInterval(timer);
            }
	},
	function () {
            if ( anim < 2 ) {
                timer = setInterval('gallery()',speed);
            }
        }
    );
}

function gallery() {
    anim++;

    var current = ($('ul.slideshow li.show')?  $('ul.slideshow li.show') : $('#ul.slideshow li:first'));
    var next = ((current.next().length) ? ((current.next().attr('id') == 'slideshow-caption')? $('ul.slideshow li:first') :current.next()) : $('ul.slideshow li:first'));
    var title = next.find('img').attr('title');
    var desc = next.find('img').attr('alt');

    next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 1000);
    current.animate({opacity: 0.0}, 1000).removeClass('show');

    if ( anim > 1 ) {
        if ( $('#main_newses').hasClass('cannot_be_opened') ) {
            clearInterval(timer);
        }
        else {
            $('#main_animation').delay(global_speed).fadeOut(1000, function() {
                $('#main_newses').fadeIn(1000);
            });
            clearInterval(timer);
        }
    }
}


