// YMH JavaScript Document - Last

// Jquery PNG Fix
// PNG Fix
    $(document).ready(function(){ 
        $(document).pngFix(); 
    }); 

// MEGA HOVER MENU
$(document).ready(function() {
	//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#mainnav li .sub").css({'opacity':'0'}); //Fade sub nav to 0 opacity on default
$("ul#mainnav li").hoverIntent(config); //Trigger Hover intent with custom configurations
});

// FACT OR FICTION JQUERY TOOLS
// What is $(document).ready ? See: http://flowplayer.org/tools/using.html#document_ready
$(function() {
	
	$("div.tabs").tabs(".images > div", {
 
		// enable "cross-fading" effect
		effect: 'fade',
		fadeOutSpeed: "slow",
 
		// start from the beginning after the last tab
		rotate: false
	// use the slideshow plugin. It accepts its own configuration
	}).slideshow({
		clickable:false,
		autoplay: false,
		interval: 3000
		});
});

// VIDEO POPUP JQUERY TOOLS
//$(function() {
//		$("a[rel]").overlay({mask: '#000', effect: 'apple'});
//});

// What is $(document).ready ? See: http://flowplayer.org/tools/documentation/basics.html#document_ready
$(document).ready(function() {
$("a[rel]").overlay({mask: '#000'});
});




// MAIL PAGE OR URL FUNCTION
function mailpage()
{
mail_str = "mailto:?subject= Check this link --> " + document.title;
mail_str += "&body= " + document.title;
mail_str += "... at: " + location.href;
location.href = mail_str;
}
var min=8;
var max=18;
function increaseFontSize() {
   var p = document.getElementsByTagName('p');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      if(s!=max) {
         s += 1;
      }
      p[i].style.fontSize = s+"px"
   }
}
function decreaseFontSize() {
   var p = document.getElementsByTagName('p');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      if(s!=min) {
         s -= 1;
      }
      p[i].style.fontSize = s+"px"
   }   
}

// External Links JavaScript Function
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") == "external")
     anchor.target = "_blank";
 }
}
window.onload = externalLinks;

