/**
 * scripts.js : Javascripts
 *
 * This file loads scripts needed for running the website. 
 * All rights reserved.
 * 
 * @version		1.0
 * @author		S.P. de Jager <s.dejager@digistyle.nl>
 * @copyright	DigiStyle Designs, may 2011
 * @see			http://www.digistyle.nl
 */

// jQuery default loaders
$(function() {  
	$(".newsticker").jCarouselLite({vertical:true,visible:1,auto:5000,speed:500});
	
	function megaHoverOver(){
		$(this).find(".sub").stop().fadeTo('fast', 1).show();
		(function($) { //Calculate width of all ul's
			jQuery.fn.calcSubWidth = function() {
				rowWidth = 0;
				$(this).find("ul").each(function() {//Calculate row				
					rowWidth += $(this).width(); 
				});	
			};
		})(jQuery); 
		
		if ( $(this).find(".row").length > 0 ) { //If row exists...
			var biggestRow = 0;	
			//Calculate each row
			$(this).find(".row").each(function() {							   
				$(this).calcSubWidth();
				if(rowWidth > biggestRow) biggestRow = rowWidth;// Find biggest row
			});
			$(this).find(".sub").css({'width' :biggestRow});
			
		} else { //If row does not exist...
			$(this).calcSubWidth();
			$(this).find(".sub").css({'width' : rowWidth});
		}
	}
	
	function megaHoverOut(){ 
	  $(this).find(".sub").stop().fadeTo('fast', 0, function() {
		  $(this).hide(); 
	  });
	}
	
	var config = {sensitivity: 2, interval: 0, over: megaHoverOver, timeout: 100, out: megaHoverOut};

	$("div.nav li .sub").css({'opacity':'0'});
	$("div.nav li").hoverIntent(config);
	$(".lasttweet").tweet().bind("loaded",function(){$(this).find("a").attr("target","_blank");});
});

// Uses IE?
var use_ie = (navigator.appVersion.indexOf("MSIE") != -1 ? true : false);


// Script to show e-mail address in javascript, prevent source-rips
function contact(user, domain, name, url, nooutput) {
	if (!domain) domain = 'body-perfection.nl';
	if (!name) name = user + '@' + domain;
	if (!url) {
		url = 'mail' + 'to:' + user + '@' + domain;
		if (!nooutput) document.write('<a href="' + url + '" title="' + name + '">' + name + '</a>'); else return url;
	} else {
		if (!nooutput) document.write(name); else return name;
	}
	return true;
}
