jQuery(document).ready(function() {	
	// Menu
	$(".header li").hoverIntent({
		sensitivity: 1, 
		interval: 1, 
		over: function() {
			$(this).addClass("selected");
			$(".sub", this).removeClass("hide").animate({opacity: .9}, 120);
		}, 
		timeout: 50, 
		out: function() {
			$(this).removeClass("selected");
			$(".sub", this).addClass("hide").animate({opacity: .0}, 100);
		}
	});
	$(".header .sub").addClass("hide");
	
	
	// blog items behaviour
	if(document.getElementById('blogLatest')) {
		$("#blogLatest #nav li").click(
			function() {				
				$(this).parent().find("li").removeClass("selected");
				$(this).addClass("selected");				
				$("#bloglist li").addClass("offleft");
				$("#bloglist li:eq("+($(this).text() - 1)+")").removeClass("offleft");
				
				return false;
			}
		);
	}
	
	$("#tweetlist").cycle({ 
		fx:     'fade', 
	    speed:   400, 
	    timeout: 8000, 
	    pause:   1
	});
	
	if(document.getElementById('heroCycle')){
		//$("#heroCycle").parent().append('<a href="#next" id="heroNext"></a><a href="#prev" id="heroPrev"></a>');
		$("#heroCycle").cycle({ 
			fx:     'fade', 
			speed:   400, 
			timeout: 8000, 
			pause:   1,
			nowrap: 0,
			prev:   '#heroPrev', 
			next:   '#heroNext'
		});
	}
	
	/*
	$(".fancybox-clients").click(
		function() {
			$(this).removeClass("hide");
		}
	);
	$(".fancybox-clients").fancybox({
		overlayOpacity: 0.8,
		'transitionIn'	:	'expoout',
		'transitionOut'	:	'expoout',
		'speedIn'		:	100, 
		'speedOut'		:	200
	});
	*/
});
$(window).bind('load', function() {
	// Flash-Text Replacement: H1
	$('.page-heading h1 strong').flash(
		{ 
			src: basePath+'interface/flash/helvetica-neue_67-medium-condensed.swf',  
			flashvars: { 
				css: [
					'* { color: #ffffff; }',
					'a { color: #ffffff; text-decoration: none; }',
					'a:hover { text-decoration: underline; }'
				].join(' ')
			},
			wmode: "transparent"
		},
		{ version: 7 },
		function(htmlOptions) {
			htmlOptions.flashvars.txt = this.innerHTML;
			this.innerHTML = '<span>'+this.innerHTML+'</span>';
			var $alt = $(this.firstChild);
			htmlOptions.height = $alt.height();
			htmlOptions.width = $alt.width();
			$alt.addClass('alt');
			$(this)
				.addClass('flash-replaced')
				.prepend($.fn.flash.transform(htmlOptions));						
		}
	);
});

var ga_source = '';
var ga_campaign = '';
var ga_medium = '';
var ga_term = '';
var ga_content = '';
var gc = '';
var c_name = "__utmz";
$(window).bind('load', function() {
	// Make GA Cookie Source Info available
	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;
			gc = unescape(document.cookie.substring(c_start,c_end));
		}
	}
	if(gc != ""){
		var z = gc.split('.'); 
		if(z.length >= 4){
		var y = z[4].split('|');
			for(i=0; i<y.length; i++){
					if(y[i].indexOf('utmcsr=') >= 0) ga_source = y[i].substring(y[i].indexOf('=')+1);
					if(y[i].indexOf('utmccn=') >= 0) ga_campaign = y[i].substring(y[i].indexOf('=')+1);
					if(y[i].indexOf('utmcmd=') >= 0) ga_medium = y[i].substring(y[i].indexOf('=')+1);
					if(y[i].indexOf('utmctr=') >= 0) ga_term = y[i].substring(y[i].indexOf('=')+1);
					if(y[i].indexOf('utmcct=') >= 0) ga_content = y[i].substring(y[i].indexOf('=')+1);
			}
		}
	}
	$("#AnalyticsTracking").val(ga_source + "/" + ga_medium + (ga_term != "" ? " ("+ga_term+")" : ""));
});

function printPage() {
	if (window.print) {
		window.print() ;
	} else {
		var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
		document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
		WebBrowser1.ExecWB(6, 2);//Use a 1 vs. a 2 for a prompting dialog box WebBrowser1.outerHTML = "";
	}
}

// Debugging
jQuery.fn.debug = function() {
  return this.each(function(){
    alert(this);
  });
};
jQuery.log = function(message) {
  if(window.console) {
     console.debug(message);
  } else {
     alert(message);
  }
};