var track_events = false;
var blank = new Image();
blank.src = '/images/blank.gif' 
var this_image = "";  
var number_of_images = "";  

$(document).ready(function() {  
	
	$("a[rel='slideshow']").colorbox({transition:"fade", photo: true});
	
	if (track_events) {
		full_page_name = page_name.toString() + "/1";
		pageTracker._trackEvent('Project image', 'View', full_page_name);
	}

	var badBrowser = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");
	if (badBrowser) {
		// get all pngs on page
		$('img[src$=.png]').each(function() {
			if (!this.complete) {
				this.onload = function() { fixPng(this) };
			} else {
				fixPng(this);
			}
		});
	} 
	
	$('a._blank').each(function() {
		alert('found a blank link');
	});
	
	$('.email').click(function(){ 
		fake_string = $(this).attr('href');
		email_arr = fake_string.split('/',3);
		$(this).attr('href','mailto:' + email_arr[1] + '@' + email_arr[2]);
	});
		
	$('#left-arrow').click(function(){
		current_left = parseInt($('#image').css("margin-left").replace("px", ""));
		new_left = current_left + 900;
		$('#image').animate({marginLeft:new_left}, 1000);
		this_image -= 1;
		decideArrowVisibility();
		trackClick();
	});
	
	$('#right-arrow').click(function(){
		current_left = $('#image').css('margin-left').replace('px', '');
		new_left = current_left - 900;
		$('#image').animate({marginLeft:new_left}, 1000);
		this_image += 1;
		decideArrowVisibility();
		trackClick();
	}); 
	                         
		decideArrowVisibility();

	
});

function decideArrowVisibility() {
	if (this_image > 1) {
		$('#left-arrow').show(); 
	} else {
		$('#left-arrow').hide();
	}
	if (this_image < number_of_images) {
		$('#right-arrow').show(); 
	} else {
		$('#right-arrow').hide();
	}
}     

function trackClick() {
	if (track_events) {
		//alert('track');
		full_page_name = page_name + "/" + this_image;
		//alert(full_page_name);
                pageTracker._trackEvent('Project image', 'View', full_page_name);
        }
}

function fixPng(png) {
	// get src
	var src = png.src;
	// set width and height
	if (!png.style.width) { png.style.width = $(png).width(); }
	if (!png.style.height) { png.style.height = $(png).height(); }
	// replace by blank image
	png.onload = function() { };
	png.src = blank.src;
	// set filter (display original image)
	png.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
}
                   
