function randomFromTo(from, to){
	return Math.floor(Math.random() * (to - from + 1) + from);
}

var img_path = '/wp-zuri/wp-content/themes/thesis/custom/images/';
/* How we Help image fade */
jQuery(document).ready(function($){
	/* Homepage widget rotator */
	//$("#widget_cycle").cycle({timeout: 9000, speed: 2000, delay: 1500});

	/* Left menu */
	$("#submenu_sidebar ul.menu li:has(ul.sub-menu)").addClass('has_sub_menu').each(function(){
		
		if( $(this).hasClass('current-menu-item') || $(this).hasClass('current-page-ancestor') ){
			$(this).addClass('submenu_active');
		}else{
			$(this).addClass('submenu_inactive');
			$(this).hover(function() {
					$(this).css('background','url('+img_path+'submenu_sidebar_link_bg_noline.png) no-repeat 0 0');
				},function () {
					$(this).css('background','url('+img_path+'submenu_sidebar_link_bg.png) no-repeat 0 -62px');
			});
		}

	});



	if( $("div.hwh_content").size){
		$("body").append('<div id="image_preloader" style="display:none;"></div>');
		$("div.hwh_content li a").each(function(){
			var thishref = $(this).attr('href');
			var thistype = thishref.substring( thishref.lastIndexOf('/')+1, thishref.length).toLowerCase();
			var thisext = thishref.substring( thishref.lastIndexOf('.')+1, thishref.length).toLowerCase();
			$("#image_preloader").append('<img src="'+thishref+'"/>');

			if(thisext=="gif" || thisext=="jpg" || thisext=="png"){
				$(this).attr('href','javascript:void(0);');
				$(this).bind("mouseover",function(){
					if( $.browser.msie){
						$("div.hwh_content div.hwh_img img").attr('src',thishref);
					}else{
						$("div.hwh_content div.hwh_img img").fadeOut(600,function(){
							$(this).remove();
							if(thistype=="email_video_sc.png"){
								$("div.hwh_content div.hwh_img").html('<a href="http://zurigroup.com/2011/email_signature_badges/"><img src="'+thishref+'" border="0" style="display:none;"/></a>')
							}else if(thistype=="hwh_products_widgets.png"){
								$("div.hwh_content div.hwh_img").html('<a href="/how-we-help/products/widgets/"><img src="'+thishref+'" border="0" style="display:none;"/></a>')
							}else{
								$("div.hwh_content div.hwh_img").html('<img src="'+thishref+'" border="0" style="display:none;"/>')
							}
							$("div.hwh_content div.hwh_img img").fadeIn();
						});
					}
				});
			}
		});
	}

	/* Social Tree */
	$(".st_icon").click(function(){

		/* Remove any existing bubbles */
		$("#social_tree_bubble").remove();

		/* Get icon position (relative to #social_tree) */
		var thisposition = $(this).parent().position();

		/* Get icon offset (relative to entire document */
		var thisoffset = $(this).offset();

		/* Position the bubble */
		if(thisposition.left >320){
			var bubble_class = 'right';
			var newleft = thisoffset.left - 650;
			var newtop = thisoffset.top - 15;
		}else{
			var bubble_class = '';
			var newleft = thisoffset.left + 20;
			var newtop = thisoffset.top - 15;
		}

		var $bubble_content = $(this).parent().find('.bcontent');
		$("#content").after('<div id="social_tree_bubble" class="'+bubble_class+'" style="left:'+newleft+'px; top: '+newtop+'px;"><div class="st_content">'+$bubble_content.html()+'</div></div>');
		$("body").click(function(){
//			alert("clicked body");
		});

	}).hover(function () {
	    $(this).addClass('handHover');
	},function () {
		$(this).removeClass('handHover');
  });


	$(".st_close").live("click",function(e){
		e.preventDefault();
		$("#social_tree_bubble").remove();
	});

});
