/* This is an archive-style image sliding library, developed by Danish Webbureau Infoserv ApS
 * A live example can be seen on scanfloor.dk
 * Note that it is developed using, and thus dependant upon, JQuery 1.2.6
 */

var containerWidth = 0;
var thumbnailWidth = 0;

if (jQuery.browser.webkit)
    $(window).load(function() {
    initSlidingImages();
});
else
    $(document).ready(function() {
    initSlidingImages();
});
 
function initSlidingImages() {    
    $('.slidingImage').each(
        function (i, img)
        {
            //Find width of containing element
            containerWidth = img.parentNode.offsetWidth;
            img.id = i.toString() + 'slidingImage';
            img = $('#' + i + 'slidingImage' );
            //img.css('margin-left',324*i);
            alert(img.id + 'rect(0px,' + (((1+i)*315)+i*9).toString() + 'px,463px,'+(i*324).toString()+'px)');
            img.css('clip','rect(0px,' + (((1+i)*315)+i*9).toString() + 'px,463px,'+(i*324).toString()+'px)');
            //img.css('z-index',Math.round(100/i));
        });
        $('.galleri_thumb').each(function (i, img) {
            thumbnailWidth += img.offsetWidth+10;
        });
        $('#galleri_thumbnails_pseudo').css('width',$($('#galleri_thumbnails_pseudo')[0]).width()+'px');
        $('#galleri_thumbnails').css('width',thumbnailWidth + 'px');
        $('#galleri_thumbnails').css('clip','rect(0px, 365px, 70px, 0px)');
        
        
}

function moveLeft()
{
    if ($.browser.version.indexOf('7')>-1 || jQuery.browser.webkit) {
            var speed = parseInt($('#galleri_thumbnails').css('clip').split(' ')[1].replace(' ',''));
        }
    else
        var speed = parseInt($('#galleri_thumbnails').css('clip').split(',')[1].replace(' ',''));
	//console.log(speed);
    $('#galleri_thumbnails').stop().animate(
        {
            clip: 'rect(0px ' + thumbnailWidth + 'px 70px ' + (thumbnailWidth-365) + 'px)',
            marginLeft: (thumbnailWidth-365)*-1+50 + 'px'
        },  thumbnailWidth/speed*1000
		
     );
}

function moveRight() {
    if ($.browser.version.indexOf('7')>-1 || jQuery.browser.webkit)
        var speed = parseInt($('#galleri_thumbnails').css('clip').split(' ')[3].replace(' ',''));
    else
        var speed = parseInt($('#galleri_thumbnails').css('clip').split(',')[3].replace(' ',''));
    speed = 1017-speed;
	//console.log(speed);
	//console.debug(thumbnailWidth-speed);
    $('#galleri_thumbnails').stop().animate(
        {
            clip: 'rect(0px 365px 70px 0px)',
            marginLeft: '50px'
        }, thumbnailWidth/speed*1000
     );
}

function stop()
{
    $('#galleri_thumbnails').stop()
}

function slidingImageMouseOver(id)
{
    if( window.navigator.userAgent.indexOf('MSIE 6')==-1)
    {
        $('.slidingImage').css('zIndex','900');
        $('#'+id).css('zIndex','1000');
        $('#'+id).stop().animate({
            clip: 'rect(0px 963px 464px 0px)'
        }, 1500 );
    }
}
                
                
function slidingImageMouseOut(id)
{
    if( window.navigator.userAgent.indexOf('MSIE 6')==-1)
        $('#'+id).stop().animate({
        clip: 'rect(0px ' + (((1+parseInt(id))*315)+parseInt(id)*9).toString() + 'px 463px '+(parseInt(id)*324).toString()+'px)'
    }, 1500 );
}
