var W,H, sW;
if (window.innerWidth) {
    W = window.innerWidth;
    H = window.innerHeight;
} else if (document.documentElement.offsetWidth) {
    W = document.documentElement.offsetWidth;
    H = document.documentElement.offsetHeight;
} else if (d.body) {
    W = document.body.offsetWidth;
    H = document.body.offsetHeight;
}

sW = screen.width;    

$(document).ready(function(){

	// handle sold image dots
/* 	$('.caption p span.caps').text('').parent().parent().parent().find('img,object').addClass('sold').after('<a class="sold" title="sold"><img src="../includes/sold.png" alt="sold" width="16" height="17" /></a>'); */

	$('.caption p span.caps').each(function(i) {
		if($(this).text() == 'SOLD'){
			$(this).text('').parent().parent().parent().find('img.artworkImage,object').addClass('sold').after('<a class="sold" title="sold"><img src="../includes/sold.png" alt="sold" width="16" height="17" /></a>');
		}
	});


	
    if($('#artists,#exhibitions').length ) {
    
        $('.holder h3 a').hide().each(function() {
            $(this)//.html($(this).text().replace(' ','<br />'))
            .fadeIn('slow');
        });
        
        $('#artists .caption').find('p:first').hide();
        
        if($('#artists').length || $('#exhibitions').length) {
            $('.emailLink a').each(function() {
                var artistName = $('.title.artists').text();
                if (artistName == '') {
	                artistName = $(this).parent().parent().find('p:first').text();
                }
                var emailLink = $(this).parent().prev().text();
                //alert(emailLink);
                $(this).attr('href','mailto:robin@robingibson.net?subject=Website enquiry: ' + artistName + ' - ' + emailLink);
                //return false;
            });
            
            $('.artworkImage').parent().hover(function() {
                
                $(this).find('.emailLink').css('visibility','visible');
            },function() {
                $(this).find('.emailLink').css('visibility','hidden');
            });
        }
        $('.menu div').hide();
        $('.menu').hover(function() {
                $(this).find('div').fadeIn('slow');
            },function() {
                $(this).find('div').fadeOut('fast');
            });
        
    }
    
    if($('#exhibitions').length ) {
		$('.linkToArtist').hide();
        if($('#exhibitions.detail').length) {
	        
            if ($('.linkToArtist:first a').attr('href') == $('.linkToArtist:last a').attr('href')) {
                // solo show
                $('.caption').find('p:first').hide();
                $('ul.imageList').not('ul.video').after('<h3 class="title artists"><a href="' + $('.linkToArtist:first a').attr('href') + '">more about the artist</a></h3>');
		        if ($('.linkToArtist').length == 1) {
			        //30Jun09 giz fix
		      		$('.posterImage').after('<h3 class="title artists"><a href="' + $('.linkToArtist:first a').attr('href') + '">more about the artist</a></h3>');
		        }
           } else {
	         
                // group show
                $('.caption').find('p:first').each(function() {
                    var artistUrl = $(this).parent().find('.linkToArtist a');
                    $(this).replaceWith('<h3 class="title artists"><a href="' + artistUrl.attr('href') + '" title="more about the artist">'+ $(this).text() + '</a></h3>');
                    
                });
           }
        } else { //list page
        
/* treat like artist list page
	        $('.exhibition .right:last').addClass('centreMe');
	        
        	if ($('.exhibition:first .holder').length ==1) {
        		$('.exhibition:first .left:last').addClass('centreMe');
        	} 
        	
        	if ($('.exhibition:eq(1) .holder').length ==1) {
        		$('.exhibition:eq(1) .left:last').addClass('centreMe');
        	} 
*/
        	
		 $('.exhibition .holder').addClass('centreMe');        	

        }
    }
    if($('#stockroom').length ) {
//         var artistPageLink = '<p><a href="../artists">' + 'more about the artist…' + '</a></p>';
//         var emailLink = '<p>' + 'email us about this work…' + '</p>';
//         $('#lightbox-overlay-text').append('<div id="artistLinks">' + artistPageLink + emailLink + '</div');
    }

});

