headgal_imags = '';
headgal_descs = '';
headgal_pagetitle = '';
headgal_paras={menu:'false',wmode:'opaque'};
headgal_flashvars={captions:'true'};
headgal_width = 725;
headgal_height = 325;

tracer=function(msg)
{
//	console.log(msg);
//	alert(msg);
}

getimages=function()
{
	tracer('images get!: '+headgal_imags);
	return headgal_imags;
}
getdescs=function()
{
	tracer('descs get!: '+headgal_descs);
	return headgal_descs;
}
getpagetitle=function()
{
	return headgal_pagetitle;
}

$(document).ready(function(){
	// case study gallery
	var gal = $("ul.gallery-menu");
	if(gal)
	{
		gal.bind("click",gallery_click);
	}
});

function embed_headgal()
{
	// header gallery
	// --------------
	var imgs = $('div#gallery-container img');
	headgal_imags = [];
	headgal_descs = [];
	imgs.each(function(i)
	{
		headgal_imags.push(this.src);
		headgal_descs.push(this.alt);
	});
	if(headgal_imags.length)
	{
		headgal_imags = headgal_imags.join(';;;');
		headgal_descs = headgal_descs.join(';;;');
	}
	
	headgal_pagetitle = $('div#gallery-container h1').text();

	swfobject.embedSWF("/assets/swf/Gallery_small.swf", "gallery-container", headgal_width, headgal_height, "9.0.0", "/assets/swf/expressInstall.swf",headgal_flashvars,headgal_paras);
	// --------------
}

// gallery functions
function gallery_click(e)
{
	var t = e.target.parentNode;
	var url = t.href;
	var title = t.title;
	var titleitem=$("h3#gallery-item-title");
	
	t.blur();
	
	// set the menu active state
	$("ul.gallery-menu li").removeClass('sel');
	$(t.parentNode).addClass('sel');
	
	if($(t).attr('rel') == 'gallery-video')
	{
		$.get('/videostub.php',{videourl:url},function(data)
											{
												$('div#CSgallery-item').empty();
												var embed = $(data).appendTo('div#CSgallery-item');
												$('div#CSgallery-item').animate({height:embed.css('height').split('px')[0]},{duration:'slow'});
												titleitem.text(' ');
												titleitem.slideUp('slow');
											});
    
	} else
	{
		// set up the gallery image
		var oldobj = $('div#CSgallery-item object').remove();
		var oldobj = $('div#CSgallery-item embed').remove();
		var oldimg = $('div#CSgallery-item img');
		var img = $('<img />').appendTo('div#CSgallery-item');
		img.hide();
		img.load(function(e)
				{
					oldimg.remove();
					$('div#CSgallery-item').animate({height:$(this).height()},{duration:'slow'});
					$(this).fadeIn('slow');
					titleitem.text(title);
					titleitem.slideDown('slow');
				});
		img.attr('alt',title);
		img.attr('src',url);
	}
	
	return false;
}
