
	$(document).ready(function() {

		$("#thispage").text("share this page: " + window.location.href);

	
	
		$(".topButton").css( { 'opacity' : '0.7' });

		$(".topButton a").each( function() {
			if ($(this).attr("href") != "#" ) {
				$(this).attr("target","_blank");
			}
		});


		$("#topNav img").hover(function(){
			$(this).fadeTo("fast", 0.6); // This should set the opacity to 60% on hover
			},function(){
			$(this).fadeTo("fast", 1.0); // This should set the opacity back to 100% on mouseout
		});

		$(".topButton").hover(function(){
			//$(this).css({'background':'#FFF'});
			//$(this).fadeOut("slow").css("background-color", "#FFFF99").fadeIn("slow");
			$(this).fadeTo("fast",1).animate({ fontSize:"+=2px" }, "fast" );
		}, function(){
			//$(this).css({'background':'transparent'});
			//$(this).fadeIn("fast").css("background-color","transparent");
			$(this).fadeTo("fast", 0.7).animate({ fontSize: "-=2px" }, "fast");
		});


		$(".sam-tabs-item-default").hover(function() {   
			if ($(this).hasClass("sam-tabs-item-selected"))
			{
			} else {
			$(this).addClass ("sam-tabs-item-hover");
			$(this).fadeTo("fast", 0.5);
			}
		}, function() {
			if ($(this).hasClass("sam-tabs-item-selected")) {
			} else {
			$(this).removeClass("sam-tabs-item-hover");
			$(this).fadeTo("fast", 0.9);
			}
		});


		$(".sam-tabs-item-default").click(function() {
			$("#topics li").removeClass("sam-tabs-item-selected");
			
			$(this).removeClass("sam-tabs-item-default");
			$(this).addClass("sam-tabs-item-selected");
			$(this).fadeTo(600,0.9);
			$(".display-window").addClass("display-window-hide");
			$(".display-window-welcome").addClass("display-window-hide");
			$(".display-window").removeAttr("style");
			$("#resources").css("z-index","0");
			$("#topics").css("z-index", "5");
			//$('#'+$(this).parent().attr('id')+'-div').removeClass("display-window-hide");
			$('#'+$(this).attr('id')+'-div').removeClass("display-window-hide").animate({width: "640px"},800, function() {
				$("#topics li").removeAttr("style").removeClass("sam-tabs-item-hover");

				});
			$("#resources li").removeClass("sam-res-item-selected");
			$('#'+$(this).attr('id')+'-div .stw1').each( function() {
				//$(this).attr("src","http://images.shrinktheweb.com/xino.php?stwembed=1&stwaccesskeyid=a393ee2aaac602a&stwsize=sm&stwurl="+$(this).parent().attr("href"));
				$(this).attr("src","http://open.thumbshots.org/image.pxf?url="+$(this).parent().attr("href"));
			});
			
			var frameid = "#"+$(this).attr('id')+'-iframe';
			if ($(frameid).attr("src") == "") {
				$(frameid).attr("src", $("#"+$(this).attr('id')+'-iframe').attr("alt")+".htm");
			}
		 
			 $(frameid).load( function() {
				$(frameid).height($(frameid).contents().find("html").height());
			 });
				
			//$("#"+$(this).attr('id')+'-iframe').height(($("#"+$(this).attr('id')+'-iframe').contents().find("html").height()));
			
		});
			
		

			
		$("#iframe-body").ready(function() {
			$('.stw1').each( function() {
					//$(this).attr("src","http://images.shrinktheweb.com/xino.php?stwembed=1&stwaccesskeyid=a393ee2aaac602a&stwsize=sm&stwurl="+$(this).parent().attr("href"));
					$(this).attr("src","http://open.thumbshots.org/image.pxf?url="+$(this).parent().attr("href"));
				});	
		});

		


		$(".sam-res-item-default").hover(function() { 
			if ($(this).hasClass('sam-res-item-selected'))
			{
			} else {
			$(this).addClass ("sam-res-item-hover");
			$(this).fadeTo("fast", 0.5);
			}
		}, function() {
			if ($(this).hasClass('sam-res-item-selected'))
			{
			} else {
			$(this).removeClass("sam-res-item-hover");
			$(this).fadeTo("fast", 0.9);
			}
		});



		$(".sam-res-item-default").click(function() {
			$("#resources li").removeClass("sam-res-item-selected");
			$(this).removeClass("sam-res-item-default");
			$(this).addClass("sam-res-item-selected");
			$(this).fadeTo(600,0.9);
			$(".display-window").addClass("display-window-hide");
			$(".display-window-welcome").addClass("display-window-hide");
			$(".display-window").removeAttr("style");
			$("#topics").css("z-index","0");
			$("#resources").css("z-index","7");
			//$('#'+$(this).parent().attr('id')+'-div').removeClass("display-window-hide");
			$('#'+$(this).attr('id')+'-div').removeClass("display-window-hide").animate({width: "640px"},800, function() {
				$("#resources li").removeAttr("style").removeClass("sam-res-item-hover");});
			$("#topics li").removeClass("sam-tabs-item-selected");
			$('#'+$(this).attr('id')+'-div .stw1').each( function() {
				//$(this).attr("src","http://images.shrinktheweb.com/xino.php?stwembed=1&stwaccesskeyid=a393ee2aaac602a&stwsize=sm&stwurl="+$(this).parent().attr("href"));
				$(this).attr("src","http://open.thumbshots.org/image.pxf?url="+$(this).parent().attr("href"));
			});
			var frameid2 = "#"+$(this).attr('id')+'-iframe';
			
			if ($(frameid2).attr("src") == "") {
				$(frameid2).attr("src", $("#"+$(this).attr('id')+'-iframe').attr("alt")+".htm");
			}
			
			$(frameid2).load( function() {
				$(frameid2).height($(frameid2).contents().find("html").height());
				
			 });

		});
			

		$(".closewindow").click(function() {
			//$(this).parent().animate({width:"446px"},1000).fadeOut(500).addClass("display-window-hide");
			//$(this).parent().addClass("display-window-hide");
			//$(this).parent().slideUp(300);
			//$(this).parent().addClass("display-window-hide");
			$("#topics li").removeClass("sam-tabs-item-selected");
			$("#resources li").removeClass("sam-res-item-selected");
			$(".display-window").addClass("display-window-hide");
			$(".display-window-welcome").removeClass("display-window-hide");
		});

	
	$(window.location.hash).trigger("click");
		
		//alert(window.parent.location + "  |  " +window.location);
		
		if ( window.parent.location == window.location)
		{
			var loc = window.parent.location+"";

			

			if (loc.indexOf("index") < 0)
			{
				//alert($("#docid").attr("title"));
				if( $("#docid").attr("title")!= null )
					window.location="index.htm"+"#"+$("#docid").attr("title");
			}
		}



	$("#slibraryshowhide").click(function() {
		if ($(".slibrary-container").css("display") == "none") {
			$(".slibrary-container").slideDown(400);
			$("#featured").animate({height: "770px"}, 400);
		} else {
			$(".slibrary-container").slideUp(400);
			$("#featured").animate({height: "600px"}, 400);
		}
	});

	$("#homepage").click(function(event) {
		
		alert("Set Breastfeeding Gateway as Homepage \n -------------------------------------  \n Internet explorer: \n 1.Open tools, click Internet Options \n 2. on the homepage, click on Use Current \n\n Firefox : \n 1. Open tools, click Options \n 2. On homepage, click use current page \n\n Chrome : \n 1. click on the wrench icon, select options \n 2. on the homepage, enter breastfeeding gateway URL \n\n Safari : \n 1. Click on gear icon, and select preference \n 2. on the homepage, click on set current page button \n\n Opera : \n 1. Click on menu -> settings -> preference \n 2. on the homepage, click on use current page \n");
		event.preventDefault();
	});

	
	$('.slibrary-prev').live("click",function() {

		$('.slibrary-next').removeClass("slibrary-btn-disable");
		$('.slibrary-next').removeAttr("style");
		$('.slibrary-next').addClass("slibrary-btn");
	
		
		if ( parseInt($('.slibrary-ul').css("left").replace("px",'')) >= -1)
		{	
			$(this).removeAttr("style");
			$(this).removeClass("slibrary-btn");	
			$(this).addClass("slibrary-btn-disable");
		} else {
			$('.slibrary-ul').animate({left:"+=197px"},900);
		}
	});

	$('.slibrary-next').live("click",function() {
		$('.slibrary-prev').addClass("slibrary-btn");
		$('.slibrary-prev').removeClass("slibrary-btn-disable");
		

		if (parseInt($('.slibrary-ul').css("left").replace("px",'')) <= -394)
		{
			$(this).removeClass("slibrary-btn");
			$(this).css("cursor","default");
			$(this).css("background-position","-144px 0");
			$(this).addClass("slibrary-btn-disable");
			
			//$(this).removeClass("slibrary-btn");	
			//$(this).addClass("slibrary-btn-disable");
			//$(".slibrary-btn-disable").unbind();
			//$(this).css("cursor","default");
			//$(this).css("background-position","-144px 0");
		} else {
			$('.slibrary-ul').animate({left:"-=197px"},900);
		}
	});




	$('.slibrary-btn').live("mouseover", function() {
		//if (! $(this).hasClass("slibrary-btn-disable")) 
		$(this).css("background-position","-48px 0px");
	});
	
	$('.slibrary-btn').live("mouseout", function() {
		$(this).removeAttr("style");
	});
	
	$('.slibrary-btn').live("mousedown",  function() {
		//if (! $(this).hasClass("slibrary-btn-disable")) 
		$(this).css("background-position","-96px 0px");
	});
	
	$('.slibrary-btn').live("mouseup", function() {
		//if (! $(this).hasClass("slibrary-btn-disable"))  {
		//$(this).removeAttr("style");
		$(this).css("background-position","-48px 0px");
		//}
	});


	$(".contentbox-content").hide();
	imagePreview();
	imagePreview2();

	$(".linkbox2-content a").each( function() {
		$(this).attr("target","_blank");
	});

	$(".linkbox2-title a").each( function() {
		$(this).attr("target","_blank");
	});


	$(".linkbox2-content .gohome").each( function() {
		$(this).attr("target","");
	});


	$(".showcontent").click( function() {
		//var getid = $(this).attr(value);
		//alert("asdad"+getid);
		//alert($(this).attr("value"));
		var getid= '#'+$(this).attr("value")
		if ($(getid).css("display") == "none")
		{
			$(getid).slideDown(400);
			$(this).text("hide [ ^ ]");
		} else {
			$(getid).slideUp(400);
			$(this).text("show [ v ]");
		}
	});





	$(".linkbox2").click( function() {
		var getid= '#'+$(this).attr("value")
		if ($(getid).css("display") == "none")
		{
			$(getid).slideDown(400);
			$(this).text("( collapse )");
		} else {
			$(getid).slideUp(400);
			$(this).text("( expand )");
		}
	});



	// jqbookmark, reference: http://calisza.wordpress.com/2008/11/03/javascript-jquery-bookmark-script/
	if(window.opera) {
        if ($("a.jqbookmark").attr("rel") != ""){ // don't overwrite the rel attrib if already set
            $("a.jqbookmark").attr("rel","sidebar");
        }
    }

	$("a.jqbookmark").click(function(event){
		event.preventDefault(); // prevent the anchor tag from sending the user off to the link
		var url = this.href;
		var title = this.title;
 
		if (window.sidebar) { // Mozilla Firefox Bookmark
			window.sidebar.addPanel(title, url,"");
		} else if( window.external ) { // IE Favorite
			window.external.AddFavorite( url, title);
		} else if(window.opera) { // Opera 7+
			return false; // do nothing - the rel="sidebar" should do the trick
		} else { // for Safari, Konq etc - browsers who do not support bookmarking scripts (that i could find anyway)
			 alert('Unfortunately, this browser does not support the requested action,'
			 + ' please bookmark this page manually.');
		}
    });

	








});  //end document ready


// image preveiw for website
this.imagePreview = function(){	
		
		xOffset1 = 10;
		yOffset1 = 10;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	$("a.webthumbnail").hover(function(f){
		
		var c = "http://images.shrinktheweb.com/xino.php?stwembed=1&stwaccesskeyid=a393ee2aaac602a&stwsize=sm&stwurl=" + this.href;
	
		$("body").append("<p id='preview'><img src='"+ c +"' alt='webpage preview'/></p>");								 
		$("#preview")
			.css("top",(f.pageY - xOffset1) + "px")
			.css("left",(f.pageX + yOffset1) + "px")
			.fadeIn("500");						
    },
	function(){
		$("#preview").remove();
    });	
	$("a.webthumbnail").mousemove(function(f){
		$("#preview")
			.css("top",(f.pageY - xOffset1) + "px")
			.css("left",(f.pageX + yOffset1) + "px");
	});			
};


// image preview for images
this.imagePreview2 = function(){	
		
		xOffset = 300;
		yOffset = 30;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	$("a.preview2").hover(function(e){
		
		var c =  $(this).attr("value");
		/* alert("<p id='preview'><img src='../images/"+ c +"' alt='preview'/></p>"); */
	
		$("body").append("<p id='preview'><img src='images/"+ c +"' alt='preview' width='300'/></p>");								 
		$("#preview")
			
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		$("#preview").remove();
    });	
	$("a.preview2").mousemove(function(e){
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};

