$j(document).ready(function() {
	
	$j('#slideshow').cycle({
		'cleartype':true,
		'cleartypeNoBg':true
	});
		
	$j("#sitemap #nav a").each(function(i){
		$j(this).appendTo($j("#quicklinks"));
		if(i % 7 == 0) {
			$j(this).addClass("first");
		}
		if(i % 7 == 6) {
			$j("#quicklinks").append('<div class="clr"></div>');
		}
	}); 
	
	$j("._1-column #shadow").attr("src","_assets/images/header-under-white.jpg");
	$j("#p_contact #shadow, #p_free-dinner #shadow").attr("src","_assets/images/header-under-contact.jpg");
	
	var featureButtons = $j("._featurebuttons");
	if(featureButtons.length > 0) {
		featureButtons.wrap('<div class="rightCol right"></div>');
		featureButtons.addClass("anchors");
		featureButtons.children().wrapAll("<dl></dl>");
		featureButtons.find("a").each(function(){
			$j(this).wrap('<dt></dt>');
		});
		featureButtons.prepend('<div class="_title">Content:</div>');
		
		var faqsAnchor = $j(".faqsAnchor");
		var testAnchor = $j(".testAnchor");
		if(faqsAnchor.length > 0) {
			faqsAnchor.appendTo("._featurebuttons dl").show();
		}
		if(testAnchor.length > 0) {
			testAnchor.appendTo("._featurebuttons dl").show();
		}
		featureButtons.show();
	}
	
	if($j("._featurebox").length > 0) {
		var img = $j("._lithoContent img");
		img.each(function() {
			var imgAlt = $j(this).attr("alt");
			var imgWidth = $j(this).width() + 8;
			if(imgAlt) {
				$j(this).wrap('<div class="imgWrap"></div>');
				$j(this).parent(".imgWrap").append('<div class="caption">'+imgAlt+'</div>');
				$j(this).parent(".imgWrap").css("width",imgWidth+"px");
			}
		});
	}
	
	$j("#baseform li").each(function(){
		$j(this).find("fieldset").last().addClass("last");
	});
	
	if($j("#youtubevideos").length > 0) {
		$j('#youtubevideos').youTubeChannel({
			userName: 'TotalHealthPMR',
			channel: "uploads",
			hideAuthor: true,
			numberToDisplay: 20
		});
		$j("#youtubevideos").delay(1000).queue(function() {
			$j("#youtubevideos .video").each(function() {
				var url = $j(this).children("a").attr("href");
				var id = getParameter(url, 'v');
				var text = $j(this).find("a").text();
				$j("#media").append('<li><a href="http://youtube.com/watch?v='+id+'" rel="lightbox" title="'+text+'"><img src="http://img.youtube.com/vi/'+id+'/0.jpg" alt="" border="0" /></a><br /><a href="http://youtube.com/watch?v='+id+'" rel="lightbox" title="'+text+'">'+text+'</a></li>');
			});
			$j("#loader").hide();
			$j("a[rel*=lightbox]").prettyPhoto();
		});
	}
	else {
		$j("#carousel").jcarousel({
			btnNext: ".next",
			btnPrev: ".prev",
			visible: 3
			//circular: false
		});
		
		$j("#carousel li").first().addClass("first");
		$j("#carousel").show();
	}
	
	$j("#tabs").tabs();
	
	// # Form Helper
	$j('label.required').append('<span class="red">**</span> ');
	$j("#baseform li").last().addClass("last");
	
	$j("#baseform.home").mouseenter(function(){
		$j(this).css("height","auto");
		$j(this).children(".formBox").css("height","auto");
		$j(this).find(".toggle").show();
	});
	
	$j("#baseform.home").mouseleave(function(){
		$j(this).css("height","320px");
		$j(this).children(".formBox").css("height","280px");
		$j(this).find(".toggle").hide();
	});
	
	// # Xray Man
	$j(".part .title").hover(function() {
		//$j(this).next(".desc").fadeIn();
		$j(".part").css("z-index","9");
		$j(this).parent().css("z-index","99999");
	}, function(){
		//$j(this).next(".desc").fadeOut();
	});
	
	
		
});
