﻿$(function() {
	//preload images
	$( ".gallery_images a" ).each(
		function( intIndex ){
			jQuery("<img>").attr("src", $( this ).attr("rel"));
		}
	);
	
	//set first
    var image = $('.image:first').attr("rel");
    $("#image").html('<img src="' + image + '" />');
	
	//start switch
	var $first = $('.gallery_images a:first');
    $first.addClass('active');
    stop_interval = setInterval("slideSwitch()", 4000);
	
	//mouseover
    $(".image").mouseover(function() {
        clearInterval(stop_interval);
        $("#image").stop();
        var image = $(this).attr("rel");
        var title = $(this).attr("title");
        $("#image").animate({ opacity: "0.0" }, 300, function() {
            $("#image").html('<img src="' + image + '" />');
        });
        $("#image").animate({ opacity: "1.0" }, 300);
        return false;
    });
	
	//click
    $(".image").click(function() {
        clearInterval(stop_interval);
        $("#image").stop();
        var image = $(this).attr("rel");
        var title = $(this).attr("title");
        $("#image").animate({ opacity: "0.0" }, 300, function() {
            $("#image").html('<img src="' + image + '" />');
        });
        $("#image").animate({ opacity: "1.0" }, 300);
        return false;
    });
});

function slideSwitch() {
    var $active = $('.gallery_images a.active');

    if ($active.length == 0) $active = $('.gallery_images a:last');

    var $next = $active.next().length ? $active.next()
        : $('.gallery_images a:first');

    $active.addClass('last-active');

    $next.addClass('active');
    $active.removeClass('active last-active');
    
    var image = $next.attr("rel");
    var title = $next.attr("title");
    $("#image").addClass('active').animate({ opacity: "0.0" }, 1000, function() {
        
        $("#image").html('<img src="' + image + '" />');
        $active.removeClass('active last-active');
    });
    $("#image").animate({ opacity: "1.0" }, 1000);    
    
}

$(function() {

});

$(document).ready(function() {
    var video = $('.video:first').attr("rel");
    var title = $('.video:first').attr("title");
    $('#video').html('<object width="530" height="353"><param name="movie" value="http://www.youtube.com/v/' + video + '&hl=en&fs=1&rel=0&autoplay=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/' + video + '&hl=en&fs=1&rel=0&autoplay=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="530" height="353"></embed></object>');
    $('#title').html(title);

    $(".video").click(function() {
        var video = $(this).attr("rel");
        var title = $(this).attr("title");
        $('#gallery').fadeIn('slow');
        $('#video').html('<object width="530" height="353"><param name="movie" value="http://www.youtube.com/v/' + video + '&hl=en&fs=1&rel=0&autoplay=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/' + video + '&hl=en&fs=1&rel=0&autoplay=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="530" height="353"></embed></object>');
        $('#title').html(title);

        return false;
    });
});


