//jQuery.noConflict();

/* delay function */
jQuery.fn.delay = function(time,func) {
	this.each(function() {
		setTimeout(func,time);
	})
	return this;
};

/* hover fade functions */
function fade_hover() {
	jQuery('.fade_hover').hover(
		function() {
				jQuery(this).stop().animate({opacity:0.4},400);
			},
			function() {
				jQuery(this).stop().animate({opacity:1},400);
		});

}


function button_hover(){
	jQuery('.button_link,button[type=submit],button,input[type=submit],input[type=button],input[type=reset]').hover(
		function() {
				jQuery(this).stop().animate({opacity:0.8},400);
			},
			function() {
				jQuery(this).stop().animate({opacity:1},400);
		});
}


function expandIt(getIt){getIt.style.display=(getIt.style.display=="none")?"":"none";}


//Update: April 12th, 10: Fixed compat issue with jquery 1.4x

//Specify full URL to down and right arrow images (23 is padding-right to add to top level LIs with drop downs):
var arrowimages={down:['', ''], right:['', '']}

var jqueryslidemenu={

animateduration: {over: 200, out: 25}, //duration of slide in/ out animation, in milliseconds

buildmenu:function(menuid, arrowsvar){
	jQuery(document).ready(function($){
		$(" #main_navigation a").removeAttr("title");

		var $mainmenu=$("#"+menuid+">ul")
		var $headers=$mainmenu.find("ul").parent()
		$headers.each(function(i){
			var $curobj=$(this)
			var $subul=$(this).find('ul:eq(0)')
			this._dimensions={w:this.offsetWidth, h:this.offsetHeight, subulw:$subul.outerWidth(), subulh:$subul.outerHeight()}
			this.istopheader=$curobj.parents("ul").length==1? true : false
			$subul.css({top:this.istopheader? this._dimensions.h+"px" : 0})
			/*
			$curobj.children("a:eq(0)").css(this.istopheader? {paddingRight: arrowsvar.down[2]} : {}).append(
				'<img src="'+ (this.istopheader? arrowsvar.down[1] : arrowsvar.right[1])
				+'" class="' + (this.istopheader? arrowsvar.down[0] : arrowsvar.right[0])
				+ '" style="border:0;" />'
			)*/
			
			$curobj.hover(
				function(e){
					var $targetul=$(this).children("ul:eq(0)")
					this._offsets={left:$(this).offset().left, top:$(this).offset().top}
					
					if(jQuery.browser.msie){
						var menuleft=this.istopheader? 0 : this._dimensions.w +2
						menuleft=(this._offsets.left+menuleft+this._dimensions.subulw>$(window).width())? (this.istopheader? -this._dimensions.subulw+this._dimensions.w : -this._dimensions.w) -4 : menuleft
					}
					if(!jQuery.browser.msie){
						var menuleft=this.istopheader? 0 : this._dimensions.w
						menuleft=(this._offsets.left+menuleft+this._dimensions.subulw>$(window).width())? (this.istopheader? -this._dimensions.subulw+this._dimensions.w : -this._dimensions.w) : menuleft
					}
					if ($targetul.queue().length<=1) //if 1 or less queued animations
						$targetul.css({left:menuleft+"px", width:this._dimensions.subulw+'px'}).slideDown(jqueryslidemenu.animateduration.over)
				},
				function(e){
					var $targetul=$(this).children("ul:eq(0)")
					$targetul.slideUp(jqueryslidemenu.animateduration.out)
				}
			) //end hover
			$curobj.click(function(){
				$(this).children("ul:eq(0)").hide()
			})
		}) //end $headers.each()
		$mainmenu.find("ul").css({display:'none', visibility:'visible'})
	}) //end document.ready
}
}
//build menu with ID="main_navigation" on page:
jqueryslidemenu.buildmenu("main_navigation", arrowimages)


jQuery(document).ready(function() {
	if(!jQuery.browser.msie){
			button_hover()
			sociable_hover();
		}   fade_hover();

	/* 
	 * Cufon 
	 */
	var $disable_cufon = jQuery("meta[name=disable_cufon]").attr('content');
	
	if($disable_cufon !='true') {
		
			Cufon.replace('h4,h5,#site_name,.dropcap1,.dropcap4,.teaser_large', { });
			Cufon.replace('#blurb,#footer_teaser_text', { textShadow: '#f9f9f9 1px 1px' });
			Cufon.replace('th,.light_gradient', {
				color: '-linear-gradient(#bbb, #888)',
				hover: 'true'
			});
			Cufon.replace('h3', {
				color: '-linear-gradient(#bbb, #888)'});
			Cufon.replace('h1,.staged_slide h2, .partial_staged_slide h2, .floating_slide h2, .full_slide h2, #body_block_background h2,.widgettitle,.dropcap2,.dark_gradient', {
				color: '-linear-gradient(#999, #4d4d4d)',
				hover: 'true',
				textShadow: '#fff 1px 1px'
			});
			Cufon.replace('.partial_gradient_slide h2', { });
			Cufon.replace('.large_button', { textShadow: '0 -1px 0 #888888' });
			
			Cufon.replace('.toggle_frame h4.toggle', {color: '-linear-gradient(#bbb, #888)',hover: 'false' });
			
			//fix flash of unstyled content with cufon
			jQuery('h1,h2,h3,h4,h5,#blurb,#site_name,.toggle,.light_gradient.dropcap1,.widgettitle,.dropcap2,.dropcap4,.teaser_large,.dark_gradient,th').each(function(){
				jQuery(this).css("text-indent", "0px");
				});

			var userAgent = navigator.userAgent.toLowerCase();
		    if(jQuery.browser.msie){
				var $ieVersion = jQuery.browser.version.substring(0,1);
				if($ieVersion == 7){
					jQuery(".dropcap1").css({paddingTop:"2px"});
				}
		    }
			
	}
		
	
	/* 
	 * tooltip functions 
	 */
	//sociable tooltip
	jQuery(".share_this_post").tooltip({ effect: 'slide', relative: false, tip: '.share_this_post_tooltip', offset: [20, 67] });

	//site search tooltip
	jQuery("#menu_search").tooltip({ effect: 'slide' , relative: true, offset: [70, -45]});

	//tooltip shortcode
	jQuery(".tooltip_btn_sc").tooltip({ effect: "slide", relative: true, offset: [20, -6], tipClass: "tool_tip" });
	jQuery(".tooltip_sc").tooltip({ effect: "slide", relative: true, offset: [20, 0], tipClass: "tool_tip" });
	jQuery(".tooltip_text").tooltip({ effect: "slide", offset: [0, 0] });


	/* 
	 * tab functions
	 */
	jQuery(function() {
		jQuery("ul.tabs").tabs("> .tab_content");
	});
	
	jQuery(function() {
		jQuery(".minimal_tab_set ul.tabs").tabs("> .tab_content");
		jQuery(".framed_tab_set ul.tabs").tabs("> .tab_content");	
	});
	

});
