var staticImgTitle, imgTitle,imgContainer,tipsPostion;
function toolTips(imgContainer, tipsPostion){
	var imgXY = $(imgContainer+ ' img').offset();
	//console.log('imgContainer',imgContainer, imgTitle);
	if(tipsPostion == 'top'){
		size = 'smallTip';
		var cssObj = {
			'position': 'absolute',
			'top': (-32)+'px',
			'left': (-60)+'px',
			'display': 'block',
			'z-index': 30000
		}
		$(imgContainer).append("<div class='tips "+size+"'></div>");
	} else {
		size = 'largeTip';
		ptop = Math.round(parseInt(imgXY.top))
		pleft = Math.round(parseInt(imgXY.left))
		var cssObj = {
			'position': 'absolute',
			'top': (ptop+225)+'px',
			'left': (pleft+115)+'px',
			'display': 'block',
			'z-index': 30000
		}
		$(".thirteenp-wrapper").append("<div class='tips "+size+"'></div>");
	} 
	$(".tips").append('<p>'+imgTitle+'</p>').css(cssObj);
}

function ml_remove(){
	$("#mailingList").remove();
}

$(document).ready(function(){
	/*global*/
	$("#nav").find("li:last").addClass('nobg');
	$("#nav li").each(function(i,ele){
		$(ele).find('ul').find('li:last').addClass('nobrd');
	});
	$("#nav li").hover(
      function () { 
			$(this).addClass("over"); 
      }, 
      function () {
		$(this).removeClass("over")
      }
    );
	
	/*home - tips*/
	var findplaywrightsAre = $(".contentContainer").find(".playwrightsAre").length;
	if (findplaywrightsAre){
		$(".playwrightsContainer li:last").addClass('nomargin')
		$(".playwrightsAre li").hover(
		  function () { 
				$(this).addClass("writer");
				var playRel = $('.playwrightsAre li.writer a').attr('rel');
				var playNum = parseInt(playRel)-1;
				imgTitle = $('.playwrightsContainer li:eq('+playNum+') img').attr('title');
				var img = '.playwrightsContainer li:eq('+playNum+')';
				toolTips(img, 'top');
		  }, 
		  function () {
			$(this).removeClass("writer");
			$('div.tips').remove();
		  }
		);
		/*set playwright stat*/
	}//findplaywrightsAre
	
	/*image tool tips*/
	var smtips = '.playwrightsContainer li.smtips';
	$(".playwrightsContainer li").hover(
		function () { 
			$(this).addClass("smtips");
			imgTitle = $(smtips+' img').attr('title');
			toolTips(smtips, 'top');
			$(smtips+' img').attr('title','');
			$(".playwrightsContainer li").each(function(s,sItem){ 
				findsmtips = $(sItem).hasClass('.smtips');
				if (findsmtips){
					$('.playwrightsAre li a').each(function(r,rEle){
						var rel = $(rEle).attr('rel');
						if ((s+1) == rel){ $('.playwrightsAre li:eq('+r+') a').addClass('select'); }
					});
				}//findsmtips
			});
		}, 
		function () {
			$(smtips+' img').attr('title',imgTitle);
			$('.playwrightsAre li a').each(function(r,rEle){ $(rEle).removeClass('select'); });
			$(this).removeClass("smtips");
			$('div.tips').remove();
		}
    );

	/*history and news*/
	var findboxesFourColumns = $().find('.boxesFourColumns').length;
	var findboxesTwoColumns = $().find('.boxesTwoColumns').length;
	if(findboxesTwoColumns){
		$('.boxesTwoColumns dl:odd').each(function(j, DL){
			$('<br clear="all" />').insertAfter(DL);
		})
	}
	
	/*bio*/
	var findBioImg = $(".contentContainer").find(".bioImg").length;
	if(findBioImg){
		/*set playwright image position*/
		$(".playwrightBox").each(function(p,ele){
			var playwrightContainer = $(ele).css("padding-bottom").split('px')[0];
			var biosHeight = $(".playwrightBox .bios").eq(p).height();
			var bioImgHeight = $(".playwrightBox .bioImg").eq(p).height();
			var biosImgPosition = biosHeight - bioImgHeight + parseInt(playwrightContainer);
			if(biosHeight > bioImgHeight){
				$(".playwrightBox .bioImg img").eq(p).css({top: biosImgPosition+"px", bottom: 0})
			}
		});
		/*set playwright image tooltips*/
		var lgtips = '.lgtips';
		$(".bioImg").hover(
		  function () { 
			$(this).addClass("lgtips");
			imgTitle = $(lgtips+' img').attr('title');
			toolTips(lgtips, 'bottom');
			$(lgtips+' img').attr('title','')
		  }, 
		  function () {
			$(lgtips+' img').attr('title',imgTitle)
			$(this).removeClass("lgtips");
			$('div.tips').remove();
		  }
		);
	}/*findBioImg-end*/
	
	/*show and hide Try This At Home*/
	$(".contentContainer").find('.showHideDiv dt').addClass('close');
	$('.showHideDiv dl').find('dd').hide().end().find('dt').click(function() {
		$('.showHideDiv').css('height','auto');
		 var details = $(this).next();
		 if (details.is(':visible')) {
			 $(this).removeClass('open').addClass('close');
			 details.hide();
		 } else {
			 $(this).removeClass('close').addClass('open');
			 details.show();
		 }
	});//showHideDiv end
	$(".contentContainer").find('.showHideDiv dl:eq(0) dt').removeClass('close').addClass('open');
	$(".contentContainer").find('.showHideDiv dl:eq(0) dd').show();
	/***end***/

	/*Mailing List*/
	var mlURL = "mailinglist.html"
	$('.mailingListIcon').click(function(e,ele){
		var findbannerLeft = ($('.banner').offset().left + $('.banner').width())-$('.banner').offset().left - 290;
		var findbannerTop = $('.banner').offset().top + $('.banner').height();
		var createMailingListDiv = $("<div class='mailingListContainer' id='mailingList'></div>");
		var createMLIframe= "<iframe frameborder='0' hspace='0' src='"+mlURL+"' id='ml_iframeContent' name='nl_iframeContent"+Math.round(Math.random()*1000)+"' frameborder='0' width='402' height='445' scrollbar='no' style='overflow:hidden;background:none;' allowtransparency='true' scrollbar='no'></iframe>";
		var closebtn = "<div class='ml_closeWindow'><a onclick='ml_remove()' href='javascript:void(0)' title='Close'><img src='/images/button/btn_ml_close.jpg' alt='close' title='close' width='280' height='28' /></a></div>"
		$('.thirteenp-wrapper').append(createMailingListDiv);
		$(".mailingListContainer").append(closebtn+createMLIframe).css({left:findbannerLeft, top:findbannerTop});
	});

}); //main documentt