$(document).ready(function(){
    $("#back").parent().hide();

	function loadCurrent(currentArt){
    	
        if (!$(currentArt).data('loaded')) {
            $("#full-art").attr('src', './images/ajax-loader.gif');
            var imageObj = new Image();
            //got to defintie onload first before defining image.src properties- only for ie6
            imageObj.onload = function(){
                $("#full-art").attr('src', this.src);
                $(currentArt).data('loaded', true);
                imageObj.onload = function(){
                }
            }
            imageObj.src = $(currentArt).attr('href');
        }
        else {
            $("#full-art").attr('src', $(currentArt).attr('href'));
        }
		if($(currentArt).is(":last-child")){$('#next').parent().css('display','none');
		}
		if($(currentArt).is(":first-child")){$('#prev').parent().css('display','none');
		} 
    }
    var currentArt = '';
    
    $(".content").css('margin-top', -($(".content").outerHeight()));
    
    $(higlightItem).addClass('current-link');
    $('#artists-nav').addClass('current-link');
    $('#selectbox').linkselect({
        change: function(li, value, text){
            window.location = './artwork.php?artist_id=' + value;
        }
    });
    
    $("#total").html($(".thumbs a").length);
    $(".thumbs a img").each(function(){
    
        var tempRef = this;
        var imageObj1 = new Image();
        imageObj1.src = $(this).attr('src');
    // $(tempRef).attr('src', './images/ajax-loader.gif');
        imageObj1.onload = function(){
           //alert('k');
		   $(tempRef).attr('src', this.src);
			         imageObj1.onload = function(){
                }
        };
        
    });
    $(".thumbs a").click(function(){
    
        currentArt = this;
        $("#art-label").html($(this).attr('alt'));
        $("#current-count").text($(".thumbs a").index($(this)) + 1);
        loadCurrent(currentArt);
        $(".content").css('margin-top', -($(".content").outerHeight()));
        previewOn();
             $("#back").parent().show();
        return false;
        
    });
    $(".thumbs a").hover(function(){
        $(".info-panel").html($(this).attr('alt'));
        $(this).css({
            'border-color': '#9FD9EC'
        });
    }, function(){
        $(this).css({
            'border-color': '#fff'
        });
    });
    $('#next').click(function(){
       	$('#prev').parent().css('display','inline');
	
        if ($(currentArt).next().attr('href')) {
            currentArt = $(currentArt).next();
            $("#art-label").html(currentArt.attr('alt'));
            $("#current-count").text($(".thumbs a").index($(currentArt)) + 1);
            
            loadCurrent(currentArt);
            
            
        }
        return false;
    });
    
    $('#prev').click(function(){
       $('#next').parent().css('display','inline');
	   if ($(currentArt).prev().attr('href')) {
        
            currentArt = $(currentArt).prev();
            $("#art-label").html(currentArt.attr('alt'));
            $("#current-count").text($(".thumbs a").index($(currentArt)) + 1);
            loadCurrent(currentArt);
            
            
        }
        return false;
    });
    
    $("#back").click(function(){
        $(this).parent().hide();
		previewOff();
    });
    
});

