﻿$(function() {
    var image = $('.image:first').attr("rel");
    var title = $('.image:first').attr("title");
    var other = $('.image:first').attr("other");
    $("#image_inner").html('<p class="image_title">' + title + '</p><img   height="210px" width="360px"  src="' + image + '" /><p class="image_description">' + other + '</p>');

    $(".image").mouseover(function() {

        clearInterval(stop_interval);

        $("#image_inner").stop();
        var image = $(this).attr("rel");
        var other = $(this).attr("other");
        var title = $(this).attr("title");
        $("#image_inner").animate({ opacity: "0.0" }, 300, function() {
        $("#image_inner").html('<p class="image_title">' + title + '</p><img   height="210px" width="360px" src="' + image + '" /><p class="image_description">' + other + '</p>');
        });
        $("#image_inner").animate({ opacity: "1.0" }, 300);


        return false;
    });
    $(".image").click(function() {
        var sdfsfsd = 1;
        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 other = $next.attr("other");
    var title = $next.attr("title");
    $("#image_inner").addClass('active').animate({ opacity: "0.0" }, 1000, function() {

    $("#image_inner").html('<p class="image_title">' + title + '</p><img   height="210px" width="360px"  src="' + image + '" /><p class="image_description">' + other + '</p>');
        $active.removeClass('active last-active');
    });
    $("#image_inner").animate({ opacity: "1.0" }, 1000);

}

function slideMoveRight() {
    var position = $(".gallery_images").position();
    var position_left = position.left - 10;
    if (position_left > -$(".gallery_images").attr("max-width")) $(".gallery_images").css("left", position_left);
    //alert($(".gallery_images").attr("max-width"));
}
function slideMoveLeft() {
    var position = $(".gallery_images").position();
    var position_left = position.left + 10;
    if (position_left < 10) $(".gallery_images").css("left", position_left);
    //alert(position_left);
}

$(function() {

	//preload images
	$( ".gallery_images a" ).each(
		function( intIndex ){
			jQuery("<img>").attr("src", $( this ).attr("rel"));
		}
	);

    var $first = $('.gallery_images a:first');
    $first.addClass('active');
    stop_interval = setInterval("slideSwitch()", 4000);

    $("#slide_right").mouseover(function() {
        stop_interval_slideMoveRight = setInterval("slideMoveRight()", 100);
        return false;
    });

    $("#slide_right").mouseout(function() {
        clearInterval(stop_interval_slideMoveRight);
        return false;
    });
	
	$("#slide_right").click(function() {
        return false;
    });

    $("#slide_left").mouseover(function() {
        stop_interval_slideMoveLeft = setInterval("slideMoveLeft()", 100);
        return false;
    });

    $("#slide_left").mouseout(function() {
        clearInterval(stop_interval_slideMoveLeft);
        return false;
    });
	
	    $("#slide_left").click(function() {
        return false;
    });
    
});