jQuery(document).ready(function(){

	// LAST CHILD : ADD FIRST / LAST CLASSES
	jQuery("li:last-child").addClass("last");
    jQuery("li:first-child").addClass("first");
    
	// ODD CHILD : ADD ODD CLASS
	jQuery("ul li:odd").addClass("odd");
	// EVEN CHILD : ADD EVEN CLASS
	jQuery("ul li:even").addClass("even");
	
	// HOME BANNER
	if(jQuery("#banner ul").children().length>1){setInterval("nextPic()", 10000)};
	
	// HEADING BREAK CLASS
	jQuery(".heading br").parent("h1").addClass("break");
	
	// CONTENT RIGHT COLUMN BG
	jQuery("#content").add_background("url('/ui/public/image/layout/content-right-column.gif') repeat-y 100% 0");
	
	// QUOTE PARAGRAH SECOND BG
	jQuery("p.quote").append("<div class=\"quote\">&nbsp;</div>");
	
	// 2 column second level nav
	$("#header .navigation li").mouseenter(function(){
		if($(this).parent().hasClass("navigation")){$(this).addClass("hover");}
	});
	$("#header .navigation li").mouseleave(function(){
		if($(this).parent().hasClass("navigation")){$(this).removeClass("hover")};
	});
	$("#header .navigation li ul").each(function(i){
		var navcnt=$(this).children().length;
		if(navcnt>6){
			var useclass="";
			if(i>3){useclass=" rightside"; $(this).css("left","-390px");}
			if(i==3){useclass=" rightside_second"; $(this).css("left","-290px");}
			var newul=$(this).parent().append("<ul class=\"second"+useclass+"\"></ul>").children("ul.second");
			$(this).css("width","480px");
			for(var j=Math.floor((navcnt+1)/2); j<navcnt; j++){
				newul.append("<li>"+$(this).children().eq(j).html()+"</li>");
			}
			var k=Math.floor((navcnt+1)/2);
			while($(this).children().length>k){
				$(this).children().eq(k).remove();
			}
		}
	});	
	
	//blog captcha after comment
	$('p.comment-form-comment').insertBefore('#recaptcha_widget_div');
	
	//Photo gallery initialize span mover for multi-level directories
	$(".gallery ul li:nth-child(1) span.desc").clone().appendTo(".gallery h3 strong");

	
	// BEFORE AFTER SLIDER
	jQuery(".example-link").attr("rel","/media/images/before-after/botox-before-small.jpg"); // HACK
	jQuery(".before-after").prepend(
		'<div id="banner-loader"></div>',
        '<div id="example"></div>'
	);
	var galleryAdv = jQuery('.before-after').galleriffic('#banner-navigation', {
		delay:                  8000,
		numThumbs:              20,
		preloadAhead:           10,
		enableTopPager:         false,
		enableBottomPager:      true,
		controlsContainerSel:   '#controls-adv',
		controlsPrev:   		'#controls-prev',
		controlsNext:   		'#controls-next',
		captionContainerSel:    '#example',
		loadingContainerSel:    '#banner-loader',
		renderSSControls:       true,
		renderNavControls:      true,
		playLinkText:           'Play Slideshow',
		pauseLinkText:          'Pause Slideshow',
		prevLinkText:           '&lsaquo; Previous',
		nextLinkText:           'Next &rsaquo;',
		nextPageLinkText:       'Next &rsaquo;',
		prevPageLinkText:       '&lsaquo; Prev',
		enableHistory:          false,
		autoStart:              false,
		onTransitionOut:        function(callback) {
			jQuery('#example').fadeTo("slow", 0.00, callback);
		},
		onTransitionIn:         function() {
			jQuery('#example').fadeTo("slow", 1);
		}
	});
	viewBa = jQuery("#left-column").attr("rel");
	if(viewBa){
		galleryAdv.goto(viewBa);
	}


});
// HOME BANNER FUNCTION
i=1;
function nextPic(){
	jQuery("#banner ul li:nth-child("+i+")").fadeOut(1500);
	i++;
	if(i>$("#banner ul").children().length){i=1;}
	jQuery("#banner ul li:nth-child("+i+")").fadeIn(1500);
}

function galnext(){
	buff=jQuery(".counter").html();
	var temp = new Array();
	temp=buff.split("/");
	cur=temp[0];
	tot=temp[1];
	jQuery("#content .main-content .gallery ul li:nth-child("+cur+")").hide();
	cur++;
	if(cur>tot){cur=1;}
	$(".gallery h3 span.desc").remove();
	$(".gallery ul li:nth-child("+cur+") span.desc").clone().appendTo(".gallery h3 strong");
	jQuery(".counter").html(cur + "/" + tot);
	jQuery("#content .main-content .gallery ul li:nth-child("+cur+")").fadeIn(500);

}

function galprev(){
	buff=jQuery(".counter").html();
	var temp = new Array();
	temp=buff.split("/");
	cur=temp[0];
	tot=temp[1];
	jQuery("#content .main-content .gallery ul li:nth-child("+cur+")").hide();
	cur--;
	if(cur<1){cur=tot;}
	$(".gallery h3 span.desc").remove();
	$(".gallery ul li:nth-child("+cur+") span.desc").clone().appendTo(".gallery h3 strong");
	jQuery(".counter").html(cur + "/" + tot);
	jQuery("#content .main-content .gallery ul li:nth-child("+cur+")").fadeIn(500);

}

