﻿
/* Scroller Code */
$.easing.easeOutQuart = function (x, t, b, c, d) {
		    return -c * ((t=t/d-1)*t*t*t - 1) + b;
	    };
	   
function changeImage(newId)
{
    var newImage = $("#" + newId);
	$("#large").attr("src", newImage.attr("href"));
    $("#imagetitle").text($("img", newImage).attr("alt"));
    //$("#main.environment .s_details .contents").text($("span", newImage).text());
    if ($(newImage).parent().prev().length)
    {
        $("#imagePrevious").attr("rel", $(newImage).parent().prev().children("a").attr("id"));
    }
    else
    {
        $("#imagePrevious").attr("rel", $(newImage).parent().parent().children().eq($(newImage).parent().parent().children().length-1).children("a").attr("id"));
    }
    if ($(newImage).parent().next().length)
    {
        $("#imageNext").attr("rel", $(newImage).parent().next().children("a").attr("id"));
    }
    else
    {
        $("#imageNext").attr("rel", $(newImage).parent().parent().children().eq(0).children("a").attr("id"));
    }
}

function randomImage()
{
    var newIndex = Math.floor(Math.random()*$(".s_environment a").length);
    changeImage($(".s_environment a:eq(" + newIndex + ")").attr("id"));
}
	    
function environment()
{
	// Add Prev/Next buttons
	var navLinks = '<p><a href="" id="imagePrevious">Previous</a> | <a href="" id="imageNext">Next</a></p>';
	$("#large").after(navLinks);

    // Add scroll buttons
    $("#slideshow").before('<a href="" class="prev"><img src="/Templates/Default/images/scroll_previous.gif" alt="Previous" title="Previous" /></a>');
    $("#slideshow").after('<a href="" class="next"><img src="/Templates/Default/images/scroll_next.gif" alt="Next" title="Next" /></a>');
    
    // Adjust styles for scroller
    $("#slideshow ul").css("width", "3900px");

    /* Add events */
	$(".s_environment a").click(
		function(){
		    changeImage($(this).attr("id"));
		    return false;
		}
	);
		
	$("#imagePrevious").click(
	    function(){
	        changeImage($(this).attr("rel"));
	        return false;
	    }
	);	
	
	$("#imageNext").click(
	    function(){
            changeImage($(this).attr("rel"));
            return false;
	    }
	);
	
	/* Add hover effect for IE6 */
	if (jQuery.browser.msie && jQuery.browser.version < 7)
	{
	    $(".s_environment a").mouseover(function(){
	        $("img", this).css("filter", "progid:DXImageTransform.Microsoft.Alpha(opacity=100)");
	    });
	    
	    $(".s_environment a").mouseout(function(){
	        $("img", this).css("filter", "progid:DXImageTransform.Microsoft.Alpha(opacity=50)");
	    });
	}

    /* Random select image initially */
	randomImage(); 
	
	/* Apply slideshow effect */
    $('#slideshow').serialScroll({
	    items:'li',
	    prev:'#scroller a.prev',
	    next:'#scroller a.next',
	    axis:'x',
	    offset:0, //when scrolling to photo, stop 230 before reaching it (from the left)
	    start:0, //as we are centering it, start at the 2nd
	    duration:1200,
	    force:true,
	    stop:true,
	    lock:false,
	    cycle:false, //don't pull back once you reach the end
	    easing:'easeOutQuart', //use this easing equation for a funny effect
	    jump: false //click on the images to scroll to them
	});
}

// Add onload ini event
attachEventListener(window, "load", environment, false)
