$(document).ready(function(){
	
	//hover states on the static widgets
 	$('.viewsource').hover(
 		function() { $(this).children('div.ui-state-default').addClass('ui-state-hover'); },
 		function() { $(this).children('div.ui-state-default').removeClass('ui-state-hover'); }
	)
	.toggle(function(){ // hide and show code examples
			$(this).parent().find('.code').show();
			$(this).find('span.ui-icon').switchClass('ui-icon-triangle-1-e', 'ui-icon-triangle-1-s', 1);
			return false;
		}, function (){
			$(this).parent().find('.code').hide();
			$(this).find('span.ui-icon').switchClass('ui-icon-triangle-1-s', 'ui-icon-triangle-1-e', 1);
			return false;
	});
	
	
	/*All thanks for Left Logic's jQuery Tabs */	
	var tabs = [];
	var tabContainers = [];
	$('ul.tabs a').each(function () {
		 // note that this only compares the pathname, not the entire url
		 // which actually may be required for a more terse solution.
		 if (this.pathname == window.location.pathname) {
			tabs.push(this);
			tabContainers.push($(this.hash).get(0));
		 }
		 $(tabContainers).hide();
		 
		 });
	
	$(tabs).click(function () {
							
		// hide all tabs
		$(tabContainers).hide().filter(this.hash).show();
		
		// set up the selected class
		$(tabs).parent().removeClass('selected');
		$(this).parent().addClass('selected');
		return false;
	}).filter(':first').click();		  	
	
	//hide all sample instructions on page load
	$('.code').hide();

	$('.demo').each(function(){
		var $clonedHtml = $(this).clone();
		$clonedHtml.find('script, style').remove();
		// remove the script and style element from the view source code;
		var currentCode = $clonedHtml.html()
		.replace("<!-- Start Entering Demo Code Here -->", "")
		.replace("<!-- InstanceBeginEditable name=\"EditDemo\" -->", "")
		.replace("<!-- InstanceEndEditable -->","")
		.replace("<!-- Stop Entering Demo Code Here -->","")
		.replace(/</g,"&lt;")
		.replace(/>/g,"&gt;");
		highlightedCode = "<h2>Demo Source Code (HTML)</h2><pre class=\"brush:xml\">"+currentCode+"</pre>";
		$(this).parent().find('.code').prepend(jQuery.trim(highlightedCode));	
	});   
	
	// highlight code
	// place last to execute on page or it'll interfere with the other js.
		var runonce = false;
		if (runonce == false){ 
		SyntaxHighlighter.config.clipboardSwf = '/lab/js/syntaxhighlighter_2.0.296/scripts/clipboard.swf';
		SyntaxHighlighter.all();
		}
		runonce = true;		
			

});
