/* SPLENDID SCRIPTS */

jQuery.noConflict();


// on DOM load:
jQuery(document).ready(function(){
//   adjust_col_1_position();
	preload_tabs();
 });
 

function adjust_col_1_position() {
	var col_1_content_height = jQuery("#col_1_content").height();
	var col_1_bottom = jQuery("#col_1").css('bottom');
	alert("col_1_bottom: " + col_1_bottom);
//	alert("col_1_content_height: " + col_1_content_height);
	var new_top = 626 - col_1_content_height;
	jQuery("#col_1_content").css('top', new_top);
}

function preload_tabs() {
	MM_preloadImages(
		'/i/shared/tabs/our_work.gif',
		'/i/shared/tabs/our_work_active.gif',
		'/i/shared/tabs/our_company.gif',
		'/i/shared/tabs/our_company_active.gif',
		'/i/shared/tabs/latest_work.gif',
		'/i/shared/tabs/latest_work_active.gif',
		'/i/shared/tabs/showreel.gif',
		'/i/shared/tabs/showreel_active.gif',
		'/i/shared/tabs/our_clients.gif',
		'/i/shared/tabs/our_clients_active.gif',
		'/i/shared/tabs/splendid_loves.gif',
		'/i/shared/tabs/splendid_loves_active.gif',
		'/i/shared/tabs/our_news.gif',
		'/i/shared/tabs/our_news_active.gif',
		'/i/shared/tabs/our_jobs.gif',
		'/i/shared/tabs/what_active.gif',
		'/i/shared/tabs/what.gif',
		'/i/shared/tabs/why_active.gif',
		'/i/shared/tabs/why.gif',
		'/i/shared/tabs/who_active.gif',
		'/i/shared/tabs/who.gif',
		'/i/shared/what_background.gif',
		'/i/shared/why_background.gif',
		'/i/shared/who_background.gif',
		'/i/shared/client_area_login_background.gif',
		'/i/shared/drop_shadow_background.png',
		'/i/shared/container_background.gif',
		'/i/shared/col_1_background.gif',
		'/i/shared/c2_background.gif',
		'/i/shared/latest_work_background.gif',
		'/i/shared/showreel_background.gif',
		'/i/shared/s2_background.gif',
		'/i/shared/s3_background.gif'
	);
}


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function show_map() {
	popup=window.open('/map/','','width='+450+',height='+450+',toolbar=no,location=no,status=no,scrollbars=no,resizable=no');
	popup.focus();
}

function show_large_map() {
	popup=window.open('/map/','','width='+560+',height='+560+',toolbar=no,location=no,status=no,scrollbars=no,resizable=no');
	popup.focus();
}

function show_large_aus_map() {
	popup=window.open('/aus_map/','','width='+560+',height='+560+',toolbar=no,location=no,status=no,scrollbars=no,resizable=no');
	popup.focus();
}

function show_europe_contact_details() {
	popup=window.open('/europe_contact_details/','','width='+740+',height='+560+',toolbar=no,location=no,status=no,scrollbars=no,resizable=no');
	popup.focus();	
}

function show_australia_contact_details() {
	popup=window.open('/australia_contact_details/','','width='+740+',height='+560+',toolbar=no,location=no,status=no,scrollbars=no,resizable=no');
	popup.focus();	
}

/*  Javascript slideshow support    */
function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function fadeIn() {
	// set opacity to 0
	changeOpac(0, 'page_2');
	// show div
	document.getElementById('page_2').style.visibility = 'visible';
	// fade in 
	opacity('page_2', 0, 99, 3000);
}

// required to support javascript slideshow
var slideshow_images = new Array();
var slideshow_image_current_position = new Array();

function make_slideshow() {
	var args = make_slideshow.arguments
	var image_id = args[0];
	slideshow_images[image_id] = new Array();
	slideshow_image_current_position[image_id] = 0;
	
	for(var i = 1; i < args.length; i++) {
		var image_filename = args[i];
		if (image_filename != 'junk') {
			// this is a global!
			slideshow_images[image_id][i] = image_filename;
		}
	}
	start_slideshow(image_id);
}


function start_slideshow(image_id) {
	// show first image
	var first_image_src = '/case_study_images/' + slideshow_images[image_id][1];
	document.getElementById(image_id).src = first_image_src;
	slideshow_image_current_position[image_id] = 1;
}


function advance_slideshow(image_id) {
	var current_position = slideshow_image_current_position[image_id];
	// is there an image in the next position?
	if (slideshow_images[image_id][current_position + 1]) {
		slideshow_image_current_position[image_id] = current_position + 1;
	} else {
		slideshow_image_current_position[image_id] = 1;
	}
	var next_image_src = '/case_study_images/' + slideshow_images[image_id][slideshow_image_current_position[image_id]];	
	document.getElementById(image_id).src = next_image_src;
}

tick_count = 5;

function advance_all_slideshows() {
	for(var the_slideshow in slideshow_image_current_position) {
		advance_slideshow(the_slideshow);		
	}
//	tick_count--;
	if (tick_count > 0) {
		setTimeout('advance_all_slideshows();', 5000);	
	}
}
