// JavaScript Document

//font size manager
function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}


function checkCookie()
{
font_size=getCookie('byon_font_size');
stdSize = 3;
  //alert('Welcome again '+font_size+'!');
  
  
  if (font_size!=null && font_size!="")
  {
 		return font_size; 
  }
else
  {
  		return stdSize;
  }
}


switchFontSize=function(ckname,val){
	var bd = jQuery("body");
	switch (val) {
		case 'inc':
			if (CurrentFontSize+1 < 7) {
				bd.removeClass('fs'+CurrentFontSize);
				CurrentFontSize++;
				bd.addClass('fs'+CurrentFontSize);
			}
		break;
		case 'dec':
			if (CurrentFontSize-1 > 0) {
				bd.removeClass('fs'+CurrentFontSize);
				CurrentFontSize--;
				bd.addClass('fs'+CurrentFontSize);
			}
		break;
		default:
			bd.removeClass('fs'+CurrentFontSize);
			CurrentFontSize = val;
			bd.addClass('fs'+CurrentFontSize);
	}
	Cookie.set(ckname, CurrentFontSize,{duration:365});
}


var title;



jQuery(document).ready(function () {

	
	/* start menu classes*/
	
	//ADD First and last classes to menu
	jQuery('ul.menu li.active ul li:first').addClass("firstItem");
	jQuery('ul.menu li.active ul li:last').addClass("lastItem");
	
	//add irst and last classes to topmenu
	jQuery('ul#topMenu').each(function(){
		
				 jQuery(this).children('li:first').addClass("firstItem");
				 jQuery(this).children('li:last').addClass("lastItem");
				 
	});

	//ADD First and last classes to menu
	jQuery('ul#matic li ul').each(function(){
		
				 jQuery(this).children('li:first').addClass("firstItem");
				 jQuery(this).children('li:last').addClass("lastItem");
				 
	});
	
	// see if ul li ul li has chidlren if yes add class haschildren
	jQuery('ul#matic li ul li'  ).each(function(){ 
			
			if  (jQuery(this).children('ul').size() > 0 ) {
    			jQuery(this).addClass("hasChildren");
			}									   
	});
	

	jQuery("ul#matic li ul li").hover(
	  function () { 	
		jQuery(this).parents('li').addClass('topMenuLeft');	
	  },
	  function () {
		jQuery(this).parents('li').removeClass('topMenuLeft');
	  }
	);
		

	if (jQuery('ul.menu ul li').hasClass("active")) {
		
		jQuery('ul.menu li.active').attr("id", "topCurrent");
		jQuery('ul.menu ul li.active').attr("id", "current");
		jQuery('ul.menu ul li ul li.active').attr("id", "currentChild");
	}
	
	if (!jQuery('ul.menu li').hasClass("active")) {
		jQuery('ul.menu li:first').addClass("active");
		//jQuery('ul.menu li.active').attr("id", "topCurrent");
	}

	if (jQuery('ul.menu li').hasClass("active")) {
		jQuery('ul.menu > li.active').attr("id", "topCurrent");
	}
						
	/* end menu classes */
	
	if (jQuery('#page iframe').hasClass("noSizeInc")) {
			jQuery('span.styleswitcher').css('display', 'none'); 
	}

	/* start dropdown code */
	
	jQuery("ul.menu_body li:even").addClass("alt");
	jQuery("ul.menu_body2 li:even").addClass("alt");
	jQuery("ul.menu_body3 li:even").addClass("alt");
	jQuery("ul.menu_body4 li:even").addClass("alt");

	
	
    jQuery('img.menu_head').click(function () {
	
		document.getElementById("onlineTools1").style.position = "relative";
		document.getElementById("onlineTools2").style.position = "static";
		document.getElementById("onlineTools3").style.position = "static";
		document.getElementById("onlineTools4").style.position = "static";
		
		jQuery('ul.menu_body').slideToggle('medium');	
		jQuery('ul.menu_body2').fadeOut('opacity:"hide"');
		jQuery('ul.menu_body3').fadeOut('opacity:"hide"');
		jQuery('ul.menu_body4').fadeOut('opacity:"hide"');


		jQuery('ul.menu_body').addClass("open");
		
		
			if (jQuery('ul.menu_body').hasClass("open")) {
					
					var alertTimerId = 0;			
				
  					jQuery("div#onlineTools1").bind("mouseenter",function(){
					clearTimeout ( alertTimerId ); 
					}).bind("mouseleave",function(){
					alertTimerId = setTimeout ( 'showAlert()', 2000 );
					});
			}

    });
	
	
	jQuery('img.menu_head2').click(function () {
	
		document.getElementById("onlineTools2").style.position = "relative";
		document.getElementById("onlineTools1").style.position = "static";
		document.getElementById("onlineTools3").style.position = "static";
		document.getElementById("onlineTools4").style.position = "static";		
		
		jQuery('ul.menu_body2').slideToggle('medium');	
		jQuery('ul.menu_body').fadeOut('opacity:"hide"');
		jQuery('ul.menu_body3').fadeOut('opacity:"hide"');
		jQuery('ul.menu_body4').fadeOut('opacity:"hide"');
		


		jQuery('ul.menu_body2').addClass("open");
		
		
			if (jQuery('ul.menu_body2').hasClass("open")) {
					
					var alertTimerId = 0;			
				
  					jQuery("div#onlineTools2").bind("mouseenter",function(){
					clearTimeout ( alertTimerId ); 
					}).bind("mouseleave",function(){
					alertTimerId = setTimeout ( 'showAlert(2)', 2000 );
					});
			}

    });
	
	
	jQuery('img.menu_head3').click(function () {
	
		document.getElementById("onlineTools3").style.position = "relative";
		document.getElementById("onlineTools1").style.position = "static";
		document.getElementById("onlineTools2").style.position = "static";
		document.getElementById("onlineTools4").style.position = "static";		
		
		jQuery('ul.menu_body3').slideToggle('medium');	
		jQuery('ul.menu_body1').fadeOut('opacity:"hide"');
		jQuery('ul.menu_body2').fadeOut('opacity:"hide"');
		jQuery('ul.menu_body4').fadeOut('opacity:"hide"');


		jQuery('ul.menu_body3').addClass("open");
		
		
			if (jQuery('ul.menu_body3').hasClass("open")) {
					
					var alertTimerId = 0;			
				
  					jQuery("div#onlineTools3").bind("mouseenter",function(){
					clearTimeout ( alertTimerId ); 
					}).bind("mouseleave",function(){
					alertTimerId = setTimeout ( 'showAlert(3)', 2000 );
					});
			}

    });
	
	
	jQuery('img.menu_head4').click(function () {
	
		document.getElementById("onlineTools4").style.position = "relative";
		document.getElementById("onlineTools1").style.position = "static";
		document.getElementById("onlineTools2").style.position = "static";
		document.getElementById("onlineTools3").style.position = "static";
		
		jQuery('ul.menu_body4').slideToggle('medium');	
		jQuery('ul.menu_body1').fadeOut('opacity:"hide"');
		jQuery('ul.menu_body2').fadeOut('opacity:"hide"');
		jQuery('ul.menu_body3').fadeOut('opacity:"hide"');


		jQuery('ul.menu_body4').addClass("open");
		
		
			if (jQuery('ul.menu_body4').hasClass("open")) {
					
					var alertTimerId = 0;			
				
  					jQuery("div#onlineTools4").bind("mouseenter",function(){
					clearTimeout ( alertTimerId ); 
					}).bind("mouseleave",function(){
					alertTimerId = setTimeout ( 'showAlert(4)', 2000 );
					});
			}

    });
	
	
	
	

	

});

function showAlert(id)	{
	
	if (typeof(id) == 'undefined') {
	id = '';
	}
	
	jQuery('ul.menu_body' + id).fadeOut('opacity:"hide"');
	jQuery('ul.menu_body' + id).addClass("closed");
	jQuery('ul.menu_body'+ id).removeClass("open");
							  
}



/* Call to launch FancyBox from Flash */
function callFancy(my_href) {
			
			var j1 = document.getElementById("hiddenclicker");
			j1.href = my_href;
			jQuery('#hiddenclicker').trigger('click');
}
		
		

			

/* Fancybox launch code*/
jQuery(document).ready(function() {
	jQuery("a.overlay-flash").fancybox({
 		'padding'                : 0,
 		'overlayOpacity'        : 0.75,
		'width'				: 820,
		'height'			: 565,
		'autoScale'     	: true,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'hideOnContentClick'    : false,
		'scrolling':	'auto',
		'type'				: 'iframe'
 	});
});
		


/*Quick Link Code*/
var tmpstate= 1;

jQuery(function() {
 	// hides the slickbox as soon as the DOM is ready (a little sooner that page load)
  	jQuery('#quickLinksMore').hide();
 	
	jQuery('#quickLinksMoreShow').click(function() {
    	jQuery('#quickLinksMore').slideToggle(750);
		
			if (tmpstate == 1) {
			jQuery('#quickLinksMoreShow').html(" - Quick Links ");
			tmpstate= 2;
			} else {
			jQuery('#quickLinksMoreShow').html(" + Quick Links ");
			tmpstate= 1;
		
		}
		return false;
  	});
});
		 
		 
/*side nav handler */
jQuery(document).ready(function () {
														 
	jQuery('table.expandTb tbody tr:first-child td').addClass('dropDownLink');
	jQuery('table.stripeTable tbody tr td').removeClass('dropDownLink');
	jQuery('ul#btmMenu li:last').addClass('lastBtmMenu');
	jQuery('#btmAdverts p:last').addClass('last');
	
	jQuery('.articlelist_intro').each(function(){ 
		jQuery('p:first', this).addClass('imageMain');
		
													   });

});

