/******************************************
Name:			homepageimageslider.js
Date:			29/05/2008
Author:			Andy Neil
Description:	Javascript file for creating the image slider on the homepage and transaction behaviour between the images

Amended:        13/08/2009
                Andrei Vais
******************************************/

function homeSliderInit()
{
    var carouselLinks = getElementsByClassName(document.getElementById("mycarousel"), "img", ["*"]);
    //console.log(carouselLinks.length);
    for(var i = 0;  i <carouselLinks.length; i++)
	{
		carouselLinks[i].onclick = function()
		{
			//console.log(this);
			setHomeFocusImage(this);
			return false;
		}
	}
}

function setHomeFocusImage(caller)
{
    if(caller.getAttribute("src"))
    {
        resetHomeImages();
        var roomShotID = caller.parentNode.getAttribute("rel");
        //console.log(roomShotID);
        caller.style.visibility = "hidden";
        
        var heading = document.getElementById("extraTitle"+roomShotID);
        var info = document.getElementById("extraInfo"+roomShotID);
        
        document.getElementById("RoomShot").firstChild.setAttribute("src", caller.getAttribute("rel"));
        document.getElementById("RoomShot").firstChild.setAttribute("alt", heading.innerHTML);
        
        document.getElementById("RoomShotNotes").getElementsByTagName("h2")[0].firstChild.nodeValue = heading.innerHTML;
        document.getElementById("RoomShotNotes").getElementsByTagName("p")[0].innerHTML = info.innerHTML;
    }
    
    return false;
}

function resetHomeImages()
{
    var shotsDiv = document.getElementById("wrap");
    var shotsImages = shotsDiv.getElementsByTagName("img");
    
    for(var i = 0;  i <shotsImages.length; i++)
	{
		shotsImages[i].style.visibility="";
	} 
}


function mycarousel_initCallback(carousel)
{
    var previousLink = getElementsByClassName(document.getElementById("wrap"), "div", ["jcarousel-prev"]);
    var nextLink = getElementsByClassName(document.getElementById("wrap"), "div", ["jcarousel-next"]);
    
    if ((previousLink.length == 1) && (nextLink.length == 1))
    {
        previousLink[0].setAttribute("title", "Click to scroll available images");
        nextLink[0].setAttribute("title", "Click to scroll available images");    
    }    
    
};

//start image scroller
jQuery(document).ready(function()
{
    jQuery('#mycarousel').jcarousel({
        scroll: 1,
        start: 3,
        initCallback: mycarousel_initCallback
    });
});
addLoadEvent(homeSliderInit);