$(document).ready(function() {

	$("a[rel='gallery']").colorbox();
	
	$("a[rel='ad']").colorbox();
	
	var url = document.URL;
	
	if ( document.URL == "http://experiencescotland.co.uk/" || document.URL == "http://experiencescotland.co.uk/index.php" || document.URL == "http://www.experiencescotland.co.uk/" || document.URL == "http://www.experiencescotland.co.uk/index.php" ){
		var t=setTimeout("popup()",3000);

	}
		

	/* Slideshow */
    $('.slideshow').cycle({
		fx: 'fade'
	});

	/* Dropdown menus */
	$("#navigation li ul").hide();

	$("#navigation li").hover(function(){
		$(this).find('ul:first').css({visibility: "visible", display: "none"}).fadeIn("200");

		$("#navigation li ul li a").hover(function(){
			$(this).addClass("active");
		}, function(){

		});
	},
	function(){
		$(this).find('ul:first').css({visibility: "hidden"});
		$("#navigation li ul li a").removeClass("active");
	});	

	var nULWidth = 170;
	var nUlCenter = nULWidth/2;
	var position, nLiWidth, nLiCenter;

	/* Lets try a script to center all the menus! */
	$("#navigation li ul").each( function( nIndex ) {
		nLiWidth = $(this).parent("li").width();		
		nLiCenter = nLiWidth/2;
		
		position = nUlCenter - nLiCenter;

		$(this).css("margin-left", "-" + (position - 5) + "px")
		
	});

});

	function popup(){
		$('#ad').bind('click', function() {
		  $("a[rel='ad']").colorbox();
		});
		$('#ad').trigger('click');	
	}

