	$(document).ready(function() {
	
	// STYLE SWITCHER begin
/**
* Styleswitch stylesheet switcher built on jQuery
* Under an Attribution, Share Alike License
* By Kelvin Luck ( http://www.kelvinluck.com/ )
**/

(function($)
{

		switchStylestyle('blue-style');
		$('.styleswitch').click(function()
		{
			switchStylestyle(this.getAttribute("rel"));
			return false;
		});
		var c = readCookie('style');
		if (c) switchStylestyle(c);


	function switchStylestyle(styleName)
	{
		$('link[@rel*=style][title]').each(function(i) 
		{
			this.disabled = true;
			if (this.getAttribute('title') == styleName) this.disabled = false;
		});
		createCookie('style', styleName, 365);
	}
})(jQuery);
// cookie functions http://www.quirksmode.org/js/cookies.html
function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name)
{
	createCookie(name,"",-1);
}
// /cookie functions
	// STYLE SWITCHER end

//On Hover Over
function megaHoverOver(){
    $(this).find(".sub").stop().fadeTo('fast', 1).show(); //Find sub and fade it in
    (function($) {
        //Function to calculate total width of all ul's
        jQuery.fn.calcSubWidth = function() {
            rowWidth = 0;
            //Calculate row
            $(this).find("ul").each(function() { //for each ul...
                rowWidth += $(this).width(); //Add each ul's width together
            });
        };
    })(jQuery); 

    if ( $(this).find(".row").length > 0 ) { //If row exists...

        var biggestRow = 0;	

        $(this).find(".row").each(function() {	//for each row...
            $(this).calcSubWidth(); //Call function to calculate width of all ul's
            //Find biggest row
            if(rowWidth > biggestRow) {
                biggestRow = rowWidth;
            }
        });

        $(this).find(".sub").css({'width' :biggestRow}); //Set width
        $(this).find(".row:last").css({'margin':'0'});  //Kill last row's margin

    } else { //If row does not exist...

        $(this).calcSubWidth();  //Call function to calculate width of all ul's
        $(this).find(".sub").css({'width' : rowWidth}); //Set Width

    }
}
//On Hover Out
function megaHoverOut(){
  $(this).find(".sub").stop().fadeTo('fast', 0, function() { //Fade to 0 opactiy
      $(this).hide();  //after fading, hide it
  });
}
//Set custom configurations
var config = {
     sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)
     interval: 100, // number = milliseconds for onMouseOver polling interval
     over: megaHoverOver, // function = onMouseOver callback (REQUIRED)
     timeout: 500, // number = milliseconds delay before onMouseOut
     out: megaHoverOut // function = onMouseOut callback (REQUIRED)
};

$("ul#topnav li .sub").css({'opacity':'0'}); //Fade sub nav to 0 opacity on default
$("ul#topnav li").hoverIntent(config); //Trigger Hover intent with custom configurations

	// TABS begin
		//if this is not the first tab, hide it
		jQuery(".tab:not(:first)").hide();
		//to fix u know who
		jQuery(".tab:first").show();
		jQuery(".htabs li:first").addClass("selected");

		//when we click one of the tabs
		jQuery(".htabs li a").click(function(){
		jQuery(".htabs li").removeClass("selected");
		jQuery(this).parent().addClass("selected");
		
		
		//get the ID of the element we need to show
		stringref = jQuery(this).attr("href").split('#')[1];
		//hide the tabs that doesn't match the ID
		jQuery('.tab:not(#'+stringref+')').hide();
		//fix
		if (jQuery.browser.msie && jQuery.browser.version.substr(0,3) == "6.0") {
		jQuery('.tab#' + stringref).show();
		}
		else
		//display our tab fading it in
		jQuery('.tab#' + stringref).fadeIn();
		//stay with me
		return false;
		});
	// TABS end

	// ALTERNATE TABLE ROW COLORS begin
		
	// ALTERNATE TABLE ROW COLORS end

	// Message Box script BEGIN
		//jQuery('.message-box').prepend('<a class="message-close float-left" title="إغلاق" href="#"><img src="images/icon_comment_delete.png" class="unitPng" alt="إغلاق"/></a>');
		//jQuery('.message-close').click( function(){
			//jQuery(this).parent().hide("slow");
			//return false;
		//});
	// Message Box script END
/*	
	// TOP NAV TOGGLE begin
		jQuery(".box-tab").hide();
		jQuery("#top-nav .wrap ul li.toggle").hover(
			function () {
				string = jQuery(this).find("a").attr("href").split('#')[1];
				jQuery('.box-tab:not(#'+string+')').hide();
				jQuery('.box-tab#' + string).show();
			},
			function () {jQuery(".box-tab").hide();	}
		);
		
		
		
		// jQuery(".box-tab").hide();
		// jQuery("#top-nav .wrap ul li a.toggle").hover(
		// function () {
		// 	string = jQuery(this).attr("href").split('#')[1];
		// 	jQuery('.box-tab:not(#'+string+')').hide();
		// 	jQuery('.box-tab#' + string).show();
		// }, 
		// function () {
		// 	jQuery(".box-tab").hide();
		// }
		// );		
		
		// ----------------------------
		
		// jQuery(".box-tab").hide();
		// jQuery("#top-nav .wrap ul li a.toggle").click(function(){
		// 	string = jQuery(this).attr("href").split('#')[1];
		// 	jQuery('.box-tab:not(#'+string+')').hide("slow");
		// 	jQuery('.box-tab#' + string).toggle("slow");
		// 	return false;
		//});
	// TOP NAV TOGGLE end
*/
	});
