// hoverIntent plugin
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);

// bgiframe plugin
(function(a){a.fn.bgiframe=(a.browser.msie&&/msie 6\.0/i.test(navigator.userAgent)?function(d){d=a.extend({top:"auto",left:"auto",width:"auto",height:"auto",opacity:true,src:"javascript:false;"},d);var c='<iframe class="bgiframe"frameborder="0"tabindex="-1"src="'+d.src+'"style="display:block;position:absolute;z-index:-1;'+(d.opacity!==false?"filter:Alpha(Opacity='0');":"")+"top:"+(d.top=="auto"?"expression(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+'px')":b(d.top))+";left:"+(d.left=="auto"?"expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+'px')":b(d.left))+";width:"+(d.width=="auto"?"expression(this.parentNode.offsetWidth+'px')":b(d.width))+";height:"+(d.height=="auto"?"expression(this.parentNode.offsetHeight+'px')":b(d.height))+';"/>';return this.each(function(){if(a(this).children("iframe.bgiframe").length===0){this.insertBefore(document.createElement(c),this.firstChild)}})}:function(){return this});a.fn.bgIframe=a.fn.bgiframe;function b(c){return c&&c.constructor===Number?c+"px":c}})(jQuery);

// Google Analytics code
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-23302929-1']);
  _gaq.push(['_setDomainName', '.janes.com']);
  _gaq.push(['_trackPageview']);

// Preloading images
jQuery.preloadImages = function() {   
     for(var i = 0; i<arguments.length; i++)   
    {
          jQuery("<img>").attr("src", arguments[i]);   
    } 
}
$.preloadImages("/public/image/fairplaydropdown_2col.png", "/public/image/ihsdropdown_2col.png");
// Preload images for IE6
if ($.browser.msie && $.browser.version.substr(0,1)<7) {
	$.preloadImages("/public/image/ie6_fairplaydropdown1.png", "/public/image/ie6_ihsdropdown1.png", "/public/image/ie6_dropdown2.png", "/public/image/ie6_dropdown3.png");	
};

// Primary Navigation dropdown code
function FPdropdownShow(){ $('#FairplayDropdown').fadeIn(150);$('#IHSDropdown').fadeOut(150);}
function FPdropdownHide(){ $('#FairplayDropdown').fadeOut(150);}
function FPdropdownShowIE(){ $('#FairplayDropdown').show();$('#IHSDropdown').hide();}
function FPdropdownHideIE(){ $('#FairplayDropdown').hide();}
function IHSdropdownShow(){ $('#IHSDropdown').fadeIn(150);$('#FairplayDropdown').fadeOut(150);}
function IHSdropdownHide(){ $('#IHSDropdown').fadeOut(150);}
function IHSdropdownShowIE(){ $('#IHSDropdown').show();$('#FairplayDropdown').hide();}
function IHSdropdownHideIE(){ $('#IHSDropdown').hide();}
$(function(){
$('#FairplayDropdown').bgiframe();
$('#FairplayDropdown ul').wrapAll('<span class="ie6fix" />');
$('#IHSDropdown ul').wrapAll('<span class="ie6fix" />');
if(jQuery.support.leadingWhitespace) {
  $('#fairplaytab').hoverIntent({
				over: FPdropdownShow, 
				timeout: 400, 
				out: FPdropdownHide
			});
  $('#ihstab').hoverIntent({
				over: IHSdropdownShow, 
				timeout: 400, 
				out: IHSdropdownHide
			});
} else {
  $('#fairplaytab').hoverIntent({
				over: FPdropdownShowIE, 
				timeout: 400, 
				out: FPdropdownHideIE
			});
  $('#ihstab').hoverIntent({
				over: IHSdropdownShowIE, 
				timeout: 400, 
				out: IHSdropdownHideIE
			});
}
});

// More Link - Add >> text
$(document).ready(function(){
	$("a.more").append('<span>&raquo;</span>');
});

// Focus input box with class=focus
$(document).ready(function(){
	$("input.focus").focus();
});

// Popup windows
$(document).ready(function(){
	$("a.popup").click(function(){
        window.open(this.href, "", "top=40,left=40,width=500,height=400,scrollbars=1"); return false;
	});
});

// Move Quick Links up if banner ad is collapsed
$(function(){
	if ( $('#pagetitle').length ) {
		var p = $("#pagetitle");
		var offset = p.offset();
		if(offset.top < 240) {
			$("#quicklinks").addClass("adcollapse");
			$("#bannerad").addClass("adcollapse");
			$("#header").addClass("adcollapse");
		}
	};
});
// Resize #mainarea when document is in full screen
if ($.browser.mozilla) {
var ffwidth = $("div.withleftnav#containerFull #mainarea").width();
$(function(){
	if (ffwidth < 1300) {
		$("div.withleftnav#containerFull #mainarea").css({"width":$(document).width() - 265});
		$(window).resize(function() {
			$("div.withleftnav#containerFull #mainarea").css({"width":$(document).width() - 265});
		});
	}
	else {
		$("div.withleftnav#containerFull #mainarea").css({"width":$(document).width() - 310});
		$(window).resize(function() {
			$("div.withleftnav#containerFull #mainarea").css({"width":$(document).width() - 310});
		});
	}
});
};
if ($.browser.msie) {
var iewidth = $("div.withleftnav#containerFull #mainarea").width();
$(function(){
	if (iewidth < 1300) {
		$("div.withleftnav#containerFull #mainarea").css({"width":$(document).width() - 290});
		$(window).resize(function() {
			$("div.withleftnav#containerFull #mainarea").css({"width":$(document).width() - 290});
		});
	}
	else {
		$("div.withleftnav#containerFull #mainarea").css({"width":$(document).width() - 335});
		$(window).resize(function() {
			$("div.withleftnav#containerFull #mainarea").css({"width":$(document).width() - 335});
		});
	}
});
};
/* Add JDW button to JDET */
$(document).ready(function () {
	if(window.location.href.indexOf("JDET") != -1)
	{
		 $("#bannerad").prepend("<div id='jdwad' style='float:right'><a href='http://www.subscription.co.uk/cc/jdwdigital'><img src='http://www2.janes.com/public/image/jdwbutton.gif' /></a></div>");
	}
});
