// Mager to change rollover state of links
$.fn.cycle.updateActivePagerLink = function(pager, currSlideIndex) { 
	$(pager).find('li').removeClass('current') 
		.filter('li:eq('+currSlideIndex+')').addClass('current'); 
}; 

// Manual slide control
function setSlide(index) {
	 $('.slides').cycle(index);
}

function launchWindow(id) {

	//Get the screen height and width
	var maskHeight = $(document).height();
	var maskWidth = $(window).width();

	//Set heigth and width to mask to fill up the whole screen
	$('#mask').css({'width':maskWidth,'height':maskHeight});
	
	//transition effect		
	$('#mask').fadeIn(1000);	
	$('#mask').fadeTo("fast",0.8);	

	//Get the window height and width
	var winH = $(window).height();
	var winW = $(window).width();
		  
	//Set the popup window to center
	$(id).css('top',  winH/2-$(id).height()/2);
	$(id).css('left', winW/2-$(id).width()/2);

	//transition effect
	$(id).fadeIn(2000); 

};

$(document).ready(function(){
	// Stop and start on mouse over banner 
	$(".country_selection ul ul").hide();
	$("a.select-country").click(function(e){
		e.preventDefault();
		$(".country_selection ul ul").slideToggle();
		$(".country_selection").mouseleave(function(e){
			$(".country_selection ul ul").hide();				
		});
	});
	
	$('#banner').mouseenter(function() { 
		$('.slides').cycle('pause'); 
	});
	$('#banner').mouseleave(function() { 
		$('.slides').cycle('resume'); 
	});

	// Cycle through slides 
	$('.slides').cycle({ 
		timeout: 3000, 
		pager:  '.banner_navigation', 
		pagerAnchorBuilder: function(idx, slide) { 
			return ''; 
		} 
	});
	
	$('.minislide').cycle({ 
		fx:    'fade', 
		speed:  2500 
	 });
	
	$("#description").hide();
	$("#related-searches").hide();
	$("#popular-searches").hide();
	
	$(".close").click(function(e){
		$(this).parent().parent().hide();
	});
	
	$(".more-information-navigation a").click(function(e){
		$(".optional").hide();
		var drawer = $(this).attr('href');
		$(drawer).slideToggle();
	});

	$(".testimonial a").fancybox({
		'modal' : true
	});
	
	$(".quickhelp").fancybox({
		'titlePosition'		: 'over',
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'width'				: '400',
		'height'			: '150',
		'autoDimensions'	: false
	});
// 	$('.quickhelptext').hide();
	
	$("a.enlarge").fancybox({	});
	
	// Profiles
	

	$('.profile_details').hide();
	// View full profile
	$('.profile a').click(function(e){
		e.preventDefault();
		var profile = $(this).attr('href');
		$('.details').hide();		
		$('.profile_details').hide();
		$(profile).fadeIn();

	});

	$('.secondary').hide();
	$('.tabs li a').click(function(e){
		// tabs
	
		$('.tabs li a').removeClass('current');
		$(this).addClass('current');
	
		e.preventDefault();
		var info = $(this).attr('href');
		
		$('.information').hide();
		$(info).fadeIn();

	});
	
	$('#archive').hide();	
	$('a.newsview').click(function(e){
		e.preventDefault();
		// tabs
	
		$('.tabs li a').removeClass('current');
		$(this).addClass('current');
	
		var info = $(this).attr('href');
		
		$('#archive').toggle();
		$('#latestnews').toggle();

	});


	
	$("a.map").fancybox({ 
		'frameWidth': 600, 'frameHeight': 360,
		'hideOnContentClick': false,
		'callbackOnClose': function() {
			$("#map").empty();
		} 
	});
	
	$(".vimeo").click(function() {
		$.fancybox({
			'padding'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'title'			: this.title,
			'width'			: 640,
			'height'		: 480,
			'href'			: this.href.replace(new RegExp("([0-9])","i"),'moogaloop.swf?clip_id=$1'),
			'type'			: 'swf'
		});
 
		return false;
	});
	$('.feature').hide();
	$('.features h3 span').click(function(e) {
		e.preventDefault();
		$(this).parent().next().slideToggle();
		$(this).toggleClass("active");

	});

});

