$(document).ready(function() {
	Cufon.replace('H1')('H2')('H3')('#main-menu LI A', {hover: true});
	//OLD BROWSER NOTIFICATION
	var notification = '<div id="browser-upgrade"><div class="upgrade-container"><p>Browser-ul tau <strong>este mult prea vechi</strong>. Versiunea pe care o folosesti are probleme si vulnerabilitati si nu afiseaza multe din functionalitatile site-ului. <strong>Iti recomandam sa instalezi o versiune noua!</strong></p><div class="browsers"><a href="http://www.google.com/chrome" title="Google Chrome" id="chrome" rel="blank"></a><a href="http://windows.microsoft.com/en-US/internet-explorer/products/ie/home" title="Internet Explorer" id="ie9" rel="blank"></a><a href="http://www.mozilla.org/en-US/firefox/new/" title="Mozilla Firefox" id="firefox" rel="blank"></a><a href="http://www.opera.com/download/" title="Opera" id="opera" rel="blank"></a><a href="http://www.apple.com/safari/download/" title="Safari" id="safari" rel="blank"></a></div><div class="clear">&nbsp;</div></div></div>';
	var b = $.browser;
	var body = $('body');
	if((b.msie && b.version < '8.0')){
		body.prepend(notification);
	}
	if((b.opera) && (b.version < '10.1')){
		body.prepend(notification);
	}
	if((b.safari) && (b.version < '3.2')){
		body.prepend(notification);
	}
	if((b.mozilla) && (b.version.slice(0,2) == '1.9')){
		body.prepend(notification);
	}
	function formatTitle(title, currentArray, currentIndex, currentOpts) {
    	return '<div>' + (title && title.length ? '<b>' + title + '</b>' : '' ) + '<br /><span>Click <a href="javascript:$.fancybox.close();" onclick="$.fancybox.close();">here</a> to close</span></div>';
	}
	$("a[rel^=lightbox]").fancybox({'overlayOpacity':'0.7', 'centerOnScroll':'false', 'imageScale': 'false', 'titlePosition':'inside','titleFormat'	: formatTitle});
	//open a link in a blank window
	$('a[rel="blank"]').click(function(){
		window.open(this.href);
		return false;
	});
	$("a[class^=iframe]").fancybox({ 'width' : 850,'height' : 600, 'overlayOpacity':'0.7', 'centerOnScroll':'false', 'imageScale': 'false', 'titlePosition' : 'inside','type' : 'iframe', 'autoScale' : 'true'});
	//menu 
	//Set custom configurations
	var config = {
	     sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)
	     interval: 10, // number = milliseconds for onMouseOver polling interval
	     over: megaHoverOver, // function = onMouseOver callback (REQUIRED)
	     timeout: 100, // number = milliseconds delay before onMouseOut
	     out: megaHoverOut // function = onMouseOut callback (REQUIRED)
	};
	$("ul#main-menu li").hoverIntent(config); //Trigger Hover intent with custom configurations
});
//open a link in a blank window
function externalLinks() { 
	if (!document.getElementsByTagName) return; 
 	var anchors = document.getElementsByTagName("a"); 
	for (var i=0; i<anchors.length; i++) { 
   		var anchor = anchors[i]; 
   		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "blank") {
	   		anchor.target = "_blank";
		} 
	}
}
window.onload = externalLinks;
//*******************************************************************************
//On Hover Over
function megaHoverOver(){
    $(this).find(".sub").stop().parent().addClass('activ');
    $(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().parent().removeClass('activ');
  $(this).find(".sub").stop().fadeTo('fast', 0, function() { //Fade to 0 opactiy
      $(this).hide();  //after fading, hide it
  });
}
//*******************************************************************************
