var $ = jQuery.noConflict();

//Cufon
jQuery(document).ready(function($){ 
	Cufon.replace('h1, h2, h3, h4, #nav li a',{
    hover: true
	});
});

jQuery(document).ready(function($){ 
	Cufon.replace('#nav li a', {
		textShadow: '0 1px 2px #000;'
	});
});

//Tabs
$(document).ready(function(){
	$('#container').tabs({ fxFade: true, fxSpeed: 'fast' });
});

//Fancybox
$(document).ready(function() { 
	 $("a.fb").fancybox(); 
	 $("a#inline").fancybox({ 'hideOnContentClick': true }); 
	 $("a.fbg").fancybox({ 'zoomSpeedIn': 300, 'zoomSpeedOut': 300, 'overlayShow': false }); 
}); 

// Tooltip script powered by jQuery (http://www.jquery.com) written by Alen Grakalic (http://cssglobe.com)
this.tooltip = function(){			
		xOffset = -20;
		yOffset = -60;		
		$("#gallery li a, #prod_skip li a").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$("#gallery li a, #prod_skip li a").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};

// starting the script on page load
$(document).ready(function(){
	tooltip();
});

//Truncate
jQuery(document).ready(function($){ 
	 $('.intro').truncate({max_length: 180});
});


//Pre and ap ends
jQuery(document).ready(function($){
    $(".unit li")
        .prepend('<span></span>');
});

jQuery(document).ready(function($){
    $("#contact_ways li")
        .prepend('<cite></cite>');
});

//Table
jQuery(document).ready(function($){
	$(".unit tr:nth-child(odd)")
	.css({"background":"#dae7f5"});
});


jQuery(document).ready(function($){
	$(".unit tr:last-child")
	.css({"background":"#fbbb83"});
});

jQuery(document).ready(function($){
	$(".unit tr.top")
	.css({"background":"#ddd"});
});

jQuery(document).ready(function($){
	$(".unit")
	.prepend('<span></span>');
});


//Gmaps - cheers Chrissyg
function initialize(){
  if (GBrowserIsCompatible()){
    var map = new GMap2(document.getElementById("google-map"));
    map.setCenter(new GLatLng(51.461004,-2.701045), 11);
    
   	var myIcon = new GIcon();
		myIcon.image = 'http://dev.duo-max.com/img/content/map/duo.png';
		myIcon.iconSize = new GSize(40,24);
		myIcon.iconAnchor = new GPoint(-139,0);
		myIcon.shadow = 'icons/shadow.png';
		myIcon.transparent = 'icons/transparent.png';
		myIcon.shadowSize = new GSize(8,8);
		myIcon.printShadow = 'icons/printShadow.gif';
		myIcon.infoWindowAnchor = new GPoint(0,-5);
		
	var markerOptions = {icon:myIcon};
	
	var markerInfo = '<div style="float:left; padding-right: 10px"><img src="http://dev.duo-max.com/img/content/map/square.jpg"/></div><ul style="float:left;"><li>DuoTech Ltd</li><li>PO Box 268</li><li>Bristol BS15 0BB</li></ul>';

    var marker = new GMarker(map.getCenter(), markerOptions);
    GEvent.addListener(marker, "click", function(){
      marker.openInfoWindowHtml(markerInfo);
    });
    map.addOverlay(marker);

   }
}


//Validate 
jQuery(document).ready(function($){
     $("#contactform").validate();  
});  

/**
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne <brian@cherne.net>
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);



//Menu dropdown
jQuery(document).ready(function($){
	function megaHoverOver(){
		$(this).find(".sub").stop().fadeTo('fast', 1).show();
			
		//Calculate width of all ul's
		(function($) { 
			jQuery.fn.calcSubWidth = function() {
				rowWidth = 0;
				//Calculate row
				$(this).find("ul").each(function() {					
					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();
				//Find biggest row
				if(rowWidth > biggestRow) {
					biggestRow = rowWidth;
				}
			});
			//Set width
			$(this).find(".sub").css({'width' :biggestRow});
			$(this).find(".row:last").css({'margin':'0'});
			
		} else { //If row does not exist...
			
			$(this).calcSubWidth();
			//Set Width
			$(this).find(".sub").css({'width' : rowWidth});
			
		}
	}
	
	function megaHoverOut(){ 
	  $(this).find(".sub").stop().fadeTo('fast', 0, function() {
		  $(this).hide(); 
	  });
	}


	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: 100, // number = milliseconds delay before onMouseOut    
		 out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
	};

	$("#nav li .sub").css({'display':'none'});
	$("#nav li").hoverIntent(config);

});

//Max Image size
/*jQuery(document).ready(function($){
	$('#content img').maxImage({
		verticalOffset: 0,
		horizontalOffset: 0,
		maxFollows: 'width',
	});
});


//Pre and ap ends
jQuery(document).ready(function($){
    $("")
        .prepend(' ');
});


$(document).ready(function(){
	$(document).ready(function () {
		$('body').addClass("none");
		$('body').fadeIn(1000);
    });
});

*/

/*
//Open in external windows
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;

//JQuery Plugin: "EqualHeights" by:	Scott Jehl, Todd Parker, Maggie Costello Wachs (http://www.filamentgroup.com) Copyright (c) 2008 Filament Group. Licensed under GPL (http://www.opensource.org/licenses/gpl-license.php)
jQuery(document).ready(function($){ 	
	function equalHeight(group) {
		tallest = 0;
		group.each(function() {
			thisHeight = $(this).height();
			if(thisHeight > tallest) {
				tallest = thisHeight;
			}
		});
		group.height(tallest);
	}

	equalHeight($ ( "#container .g4" ) );
	
});

// Tooltip script powered by jQuery (http://www.jquery.com) written by Alen Grakalic (http://cssglobe.com)
this.tooltip = function(){	
			
		xOffset = 10;
		yOffset = 20;		
	$(".tooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$(".tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};

// starting the script on page load
$(document).ready(function(){
	tooltip();
});
*/


