$(document).ready(function(){   	
	nivoSlider();
	newsbar();	
});

function asyncImagesLoad(){
    $('.imgLoader').asyncLoader();
}


function nivoSlider(){	
	    		
    $('#sliderContainer').nivoSlider({
		effect: 'random',
		animSpeed: 1500,
		pauseTime: 5000,
		startSlide: 2,
		directionNav: true,
		controlNav: false,
		pauseOnHover: false,
		slices:20,
		captionOpacity:0.8
	}); 
}

function newsbar(){
	var container = $('#newsbar').css({display:'block'});
    var interval = '';
    var element = $(".news_text").find("li");
    var element_Count = element.length;
	var current_elem = $(".news_text").find('.visible').css({zIndex : element_Count + 1});
    current_element = element.not(element[0]).css({
        opacity: 0.0
    });
    
    interval = setInterval(function(){
        fade();
    }, (parseInt(3) * 1500));
    
    function fade(){
    
        var current_elem = $('ul.news_text').find('.visible').css({zIndex: element_Count});
        var next_elem = current_elem.next();
        
        if (next_elem.length == 0) {
            next_elem = $(element[0])
        }       
        
        $(current_elem).css({
            zIndex: element_Count
        }).stop().animate({
            opacity: 0
        }, 350, 'easeOutExpo');
        
        current_elem.removeClass('visible');
        
        next_elem.addClass('visible').css({
            zIndex: element_Count + 1
        }).stop().animate({
            opacity: 1
        }, 1500, 'easeOutExpo');
    }
    
	$("#newsbar").hover(function()
	{
		clearInterval(interval);					
	},function(){
		interval = setInterval(function(){
        fade();
    }, (parseInt(3) * 1500));
	});
}

function projectpreview(){

    var imgHolder = $('body').find('a.imgLoader').css({
        'display': 'block'
    });
    
    imgHolder.each(function(){
        $(this).hover(function(){
            var ImgChecker = new RegExp(/\.(gif|jpe?g|png|bmp)$/);
            var VideoChecker = new RegExp(/\.(flv|mpe?g|swf|avi|flv)/);
            var YoutubeChecker = new RegExp(/(youtube.com)/);
            var VimeoChecker = new RegExp(/(vimeo.com)/);
            
            var $this = $(this);
            var hovredImg = $(this).find('img');
            
            var cover = $("<div class='cover'></div>").css({
                position: 'absolute',
                top: hovredImg.position().top,
                left: hovredImg.position().left,
                height: hovredImg.height(),
                width: hovredImg.width(),
                opacity: 0.0
            });
            
            if (ImgChecker.test($this.attr("href"))) {
                $(cover).addClass('imgCover').appendTo($this).stop().animate({
                    opacity: 0.5
                });
            }
            else 
                if (VideoChecker.test($this.attr("href"))) {
                    $(cover).addClass('videoCover').appendTo($this).stop().animate({
                        opacity: 0.5
                    });
                }
                else 
                    if (YoutubeChecker.test($this.attr("href"))) {
                        $(cover).addClass('video_YoutubeCover').appendTo($this).stop().animate({
                            opacity: 0.5
                        });
                    }
                    else 
                        if (VimeoChecker.test($this.attr("href"))) {
                            $(cover).addClass('video_VimeoCover').appendTo($this).stop().animate({
                                opacity: 0.5
                            });
                        }
                        else {
                            $(cover).css({
                                background: "#000"
                            }).appendTo($this).stop().animate({
                                opacity: 0.5
                            });
                        }
        }, function(){
            $(this).find('.cover').stop().animate({
                opacity: 0.0
            }, function(){
                $(this).remove();
            });
        });
    });
}

function prettyPhoto(){

	$("a[rel^='prettyPhoto']").prettyPhoto({
		theme: 'light_square'
	});
}


