// for IE6 background flicker
try {
	document.execCommand( 'BackgroundImageCache', false, true );
}catch(e){}


function scrollStyle(){
	$('#inframe').jScrollPane({showArrows:true, scrollbarWidth:16, arrowSize:16});
}

function colorbox(){
	$('.clip').colorbox({opacity:0.95});
	$("a[rel^='cb']").colorbox({opacity:0.95});

	$('#gallery a')
		.fadeTo(1,0.5)
		.hover(
			function(){ $(this).fadeTo(200,1.0) },
			function(){ $(this).fadeTo(500,0.5) }
		);

	$('#clips img')
		.fadeTo(0.5,1)
		.hover(
			function(){ $(this).fadeTo(200,0.5) },
			function(){ $(this).fadeTo(500,1.0) }
		);

	$.ajax({
	    type: "GET", 
	    url: "projects.xml",
	    dataType: "xml",
	    success: function(xml){
	        $(xml).find("proj").each(function(){
				var $proj = $(this).text();
				var $link = "<a id=\"proj-" + $proj + "\" href=\"#\"><img src=\"projects/" + $proj + "_s.jpg\"></a>\n";

			    $("#inframe2").append($link);
	        });

			$('#inframe2 img')
				.fadeTo(0.5,1)
				.hover(
					function(){ $(this).fadeTo(200,0.5) },
					function(){ $(this).fadeTo(500,1.0) });
				
			$('#inframe2 a')
				.click(function(){
					var $id = $(this).get(0).id.replace('proj-','');

					$('#inframe3').hide();
					$('#inframe3').load('projects/'+$id+'.html',function(){});
					$('#inframe3').fadeIn('fast');
			});

			$('#inframe3').load('projects/monsterSamurai.html',function(){});
		}
	});
}

function buildSubmenu( $page, $trgt ){
	for( $i=1; $i<=$page.length; $i++ ){
		$('#'+$trgt+$i+' a').removeAttr('href').click(function(){
			var $id = $(this).parent().get(0).id.replace($trgt,'');
			var $pg = $id - 1;
			$id = $trgt + $id;

			if( !$(this).is('.'+$id+'s') ){
				for( $j=1; $j<=$page.length; $j++ )
					$('#'+$trgt+$j+' a').removeClass().attr('style','cursor:pointer');

				$('#contentBox').hide();

				if( $trgt=='wrk' ){
					$('#contentBox').load($page[$pg]+'.php #content',function(){scrollStyle();colorbox();});
				}else{
					$('#contentBox').load($page[$pg]+'.php #content',function(){scrollStyle()});
				}

				$('#contentBox').fadeIn('fast');
				$('#'+$id+' a').addClass($id+'s').removeAttr('style');
			}
		});

		if( $i!=1 )
			$('#'+$trgt+$i+' a').attr('style','cursor:pointer');
	}
}


$(document).ready(function(){
	buildSubmenu( $page, $trgt );
	scrollStyle();
});


