﻿$(document).ready(function() {
	
	var url = location.pathname;
	//var url = document.location.toString();
	//alert(url);
	
	//subscribe box animation
	
	//modal background
	var background = $(".modalPopupTransparent");


$("a.subscribeFormLink").click(function() {
	
	//show the background
	$(background).css({width: screen.width});				
	$(background).css({height: screen.height});
	$(background).show();
	
	//show the form
	$("#subscribeForm").animate({
    opacity: 'show',
    height: 'toggle'
	}, 500, function() {
    // Animation complete.
  	});
	
	

});

$("a.closeIcon").click(function() {
								
								
								
	//hide the form							
	$("#subscribeForm").animate({
    opacity: 'hide',
    height: 'toggle'
	}, 500, function() {
    // Animation complete.
  	});
	//hide the background
	$(background).css({width: screen.width});				
	$(background).css({height: screen.height});
	$(background).hide();	
});
	
	
	
	$("#topNavigation ul li:last-child a").addClass("last");
	
	if(location.pathname.indexOf('Regions') > 0 || location.pathname.indexOf('Destinations') > 0){
		$("#topNavigation ul li:eq(1) a").addClass("active");
	}
	
	// if (url.indexOf("Regions") || url.indexOf("Destinations")) {
    	//$("#topNavigation ul li:last-child a").addClass("active");
  	//}

	
	
	$(".bannerNavigation a:first").addClass("active");
	var contentwidth = $(".bannerContainer").width();
	var totalcontent = $(".bannerContent").size();
	var allcontentwidth = contentwidth * totalcontent;
	$(".bannerSlides").css({'width' : allcontentwidth});
	
	rotate = function(){
		var slideid = $active.attr("rel") - 1;
		var slidedistance = slideid * contentwidth;
		$(".bannerNavigation a").removeClass('active');
		$active.addClass('active');
		$(".bannerSlides").animate({left: -slidedistance}, 500 );
	}; 
	
	rotation = function(){
		play = setInterval(function(){
		$active = $('.bannerNavigation a.active').next();
		if ( $active.length === 0) {
			$active = $('.bannerNavigation a:first');
		}
		rotate();
		//Timer speed 5 sec
		}, 5000);
	};
	
	rotation();
	
	$(".bannerNavigation a").click(function() {
		$active = $(this);	
		clearInterval(play);
		rotate();
		rotation();
		return false;
	});
	
	/*
	// To make the whole btn clickable on the home page
	$(".home_button").click(function(){
			$(this).css('cursor:pointer');							 
			 window.location=$(this).find("p.click_here a").attr("href");
		 return false;
	});
	*/
	
});




function openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function openModalWindow(passedDiv, passedBgDiv) {

    var bgDiv = $(passedBgDiv);
    bgDiv.width($(window).width());
    bgDiv.height($(document).height());
    bgDiv.show();


    var popUpDivName = $(passedDiv);
             
	//get the size of the window and calculate where the box should be placed        
    popUpDivName.css('top', (($(document).height() - popUpDivName.height() * 2) / 2) + 'px');
    popUpDivName.css('left', (($(window).width() - popUpDivName.width()) / 2) + 'px');
    if (popUpDivName.height() > $(window).height()) {
        popUpDivName.css('top', '20px');        
    }        
   
}

function closeModalWindow(passedDiv, passedBgDiv) {

    var bgDiv = $(passedBgDiv);
    var popUpDivName = $(passedDiv);
    bgDiv.hide();
    popUpDivName.hide();
}


// sprott websites modal window
$(document).ready(function () {    
    $(".sprott-websites").colorbox({ width: "950px", height: "450px", scrolling: false, iframe: true });
});
