
	
	var player_width;
	var current_thumbs = 0;
	var next_vid;
	var next_catonly = false;
	
	var def_thumb_txt = "<a href='http://www.profiles.net.au/main.asp?AID=628212' target='_blank'><img alt='JobFit' border='0' style='margin: 0 0 3px 3px;' src='resources/images/JobFikt001.jpg' align='right'/><p style='font-weight: normal;font-size: 11px'>Use our JobFit online tool to gain general insight into the types of careers that may suit your occupational interests.</p></a>";
	
	function find_node(find)
	{
		for(i in data)
		{
			var node = data[i];
			var category = node.category;
			if (category == find)
			{
				return node;
			}
		}
	}
	
	function next_video(find)
	{
		var next = false;
		
		for(i in data)
		{
			if (next_catonly) next = false;
			
			var node = data[i];
			var category = node.category;
			var vids = node.videos;
			for (x in vids)
			{
				var file = vids[x].file;
				if (next) return file;
				
				if (file == find) next = true;
			}
			
		}
	}
	
	function find_desc(find)
	{
		var i = 0;
		for(i in data)
		{
			var node = data[i];
			var vids = node.videos;
			var autoplay = false;
			
			
			for (x in vids)
			{
				var file = vids[x].file;
				i++;
				
				if (file == find) return vids[x];
				
			}
		}
	}
	
	function build_all()
	{
		current_thumbs = 0;
		var autoplay = false;
		for(i in data)
		{
			var node = data[i];
			var category = node.category;
			//alert(category);
			var vids = node.videos;

			for (x in vids)
			{
				var file = vids[x].file;
				current_thumbs++;
				var thumb = "resources/flv/thumbs/"+vids[x].file+".jpg";	
				$("#thumbs #images").append("<span rel='"+vids[x].file+"'><img src='"+thumb+"' alt='Thumb'/></span>");
				
				if (!autoplay)
				{
					autoplay = file;
				}
			}
		}
		
		var node = find_node(0);
		
		do_more(node.more,node.title);
		
		play_thumb(autoplay);
		next_catonly = false;
		thumbs_assign();
	}
	
	function build_category(find,all)
	{
		next_catonly = true;
		$("#thumbs #images").html('');
		
		var node = find_node(find);
		var title = node.title;
		var vids = node.videos;
		
		do_more(node.more,node.title);
		
		var autoplay = false;
		current_thumbs = 0;
		
		for (x in vids)
		{
			var file = vids[x].file;
			var thumb = "resources/flv/thumbs/"+vids[x].file+".jpg";
			current_thumbs++;

			$("#thumbs #images").append("<span rel='"+vids[x].file+"'><img src='"+thumb+"' alt='Thumb'/></span>");
			
			if (!autoplay)
			{
				autoplay = file;
			}
		}
		play_thumb(autoplay);
		thumbs_assign();
	}
	
	function do_more(more,title)
	{
		if (more)
		{
			//more = "<h2>"+title+"</h2>" + more;
			
			//$("#information #morecontent").html(more);
			$("#information").hide();
			$("#moreinfo").show();
		} else {
			//$("#information #morecontent").html('');
			$("#information").hide();
			$("#moreinfo").hide();
		}
	}
	
	function thumbs_assign()
	{
		$("#thumbs #images").animate({"marginLeft": "0px"}, "fast", function(){toggle_left_right();});
		
		$("#thumbs #images span").click(function(){			
			play_thumb($(this).attr('rel'));
			var node = find_desc($(this).attr('rel'));
			var thumb = node;
			
			//alert(node[1]+" of "+node[2]);
			
		}).mouseover(function(){
			var node = find_desc($(this).attr('rel'));
			var thumb = node;
			$("#infobox td").html("<p>"+thumb.desc+"</p>");
			$("#infobox").addClass('lg');
		}).mouseout(function(){
			$("#infobox td").html(def_thumb_txt);
			$("#infobox").removeClass('lg');
		});
	}
	
	function play_thumb(rel)
	{
		
		next_vid = next_video(rel);

		var node = find_desc(rel);
		var video = node;
		
		if (!video) return;
		
		//do we need to move the stage for autoplay?
		$("span.on").removeClass("on");
		$("span[@rel="+rel+"]").addClass("on");
		
		if (navigator.appName.indexOf("Microsoft Internet")>=0)
		{
			var tt_ol = getRealLeft($("span.on").get(0));
			if (tt_ol > 650) shift_right();
		} else {
			var tt_ol = $("span.on").attr('offsetLeft');
			if (tt_ol > 650) shift_right();
		}

		
		$("span.on").fadeTo("fast",1);
		$("span").not(".on").fadeTo("fast",0.8);

		
		
		setTimeout(function(){
			var flashMovie = getFlashMovieObject("videoplayer");
			flashMovie.SetVariable("vidurl","../flv/"+mode+"/"+rel);
			flashMovie.SetVariable("title_txt",video.title);
			
			flashMovie.Play();
		},300);
		
		setTimeout(function(){
			var flashMovie = getFlashMovieObject("videoplayer");
			if (next_vid) flashMovie.SetVariable("nextvid",next_vid);
			else flashMovie.SetVariable("nextvid",false);
		},1000);
	}
	
	function getRealLeft(tempEl){
		var L=0;
		while(tempEl.parentNode){
			L+= (tempEl.offsetLeft)?tempEl.offsetLeft:0;
			if(tempEl == document.body) break;
			tempEl = tempEl.parentNode;
		}
		return L;
	}

	$(document).ready(function(){
		
		$("#infobox td").html(def_thumb_txt);
		
		$("#information, #moreinfo, #left, #main, #right, #menu").addClass(mode);
		
		for(i in data)
		{
			var node = data[i];
			$("#menu ul").append("<li><a href='#' rel='"+node.category+"'>"+node.title+"</a></li>");
		}
		
		if (mode == 'large')
		{
			var swf_w = 564;
			var swf_h = 388;
		} else {
			var swf_w = 470;
			var swf_h = 323;
		}
		
		$("#player").html('\
				<object width="'+swf_w+'" height="'+swf_h+'" id="videoplayer">\
					<param name="movie" value="resources/swf/video_player_small.swf"/>\
					<param name="wmode" value="transparent"/>\
						<embed src="resources/swf/video_player_small.swf" width="'+swf_w+'" wmode="transparent" height="'+swf_h+'" name="videoplayer" swliveconnect="true"/>\
					</embed>\
				</object>\
		');
		
		$("#menu ul a").click(function(){
			build_category($(this).attr('rel'));
			return false;
		}).mouseover(function(){
			var node = find_node($(this).attr('rel'));
			$("#infobox td").html("<p>"+node.desc+"</p>");
			$("#infobox").addClass('dg');
		}).mouseout(function(){
			$("#infobox td").html(def_thumb_txt)
			$("#infobox").removeClass('dg');
		});
		
		$("#player").mouseout(function(){
			var flashMovie = getFlashMovieObject("videoplayer");
			flashMovie.SetVariable("show_controls","false");
		}).mouseover(function(){
			var flashMovie = getFlashMovieObject("videoplayer");
			flashMovie.SetVariable("show_controls","true");
		});
		
		//build_all();
		build_category(0);
	});
	
	function getFlashMovieObject(movieName)
	{
		if (window.document[movieName]) 
		{
			return window.document[movieName];
		}
		if (navigator.appName.indexOf("Microsoft Internet")==-1)
		{
			if (document.embeds && document.embeds[movieName])
			return document.embeds[movieName]; 
		}
		else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
		{
			return document.getElementById(movieName);
		}
	}
	
	function shift_right()
	{
		var ml = parseInt($("#thumbs #images").css("margin-left"));
		var mw = parseInt("-"+(current_thumbs * 90)) + parseInt($("#thumbs #scroller").css("width"));
		
		if (ml >= mw) $("#thumbs #images").animate({"marginLeft": "-="+parseInt($("#thumbs #scroller").css("width"))+"px"}, "slow",function(){toggle_left_right();});
	}
	
	function shift_left()
	{
		var ml = parseInt($("#thumbs #images").css("margin-left"));
		if (ml != 0) $("#thumbs #images").animate({"marginLeft": "+="+parseInt($("#thumbs #scroller").css("width"))+"px"}, "slow",function(){toggle_left_right();});
		
		
	}
	
	function toggle_left_right()
	{
		var ml = parseInt($("#thumbs #images").css("margin-left"));
		
		var mw = parseInt("-"+(current_thumbs * 90)) + parseInt($("#thumbs #scroller").css("width"));
		if (ml >= mw) $("#right_thumbs").fadeTo('fast',1);
		else $("#right_thumbs").fadeTo('fast',0.2);
		
		if (ml != 0) $("#left_thumbs").fadeTo('fast',1);
		else $("#left_thumbs").fadeTo('fast',0.2);
	}
	
	function moreInfo()
	{
		var flashMovie = getFlashMovieObject("videoplayer");
		flashMovie.SetVariable("playpause",true);
		
		$("#information").slideToggle();
	}
	