function SwitchBox(id) {
	for(var i=1 ; i <= 5; i++) {
		$("#txt" + i).hide();
		$("#tab-" + i + " a:first-child").removeClass("selected-box");
		$("#tab-" + i + " a:first-child").removeClass("not-selected-box");
		if (id != i) {
			$("#tab-" + i + " a:first-child").addClass("not-selected-box");
		} else {
			$("#tab-" + i + " a:first-child").addClass("selected-box");				
		}				
	}
	$("#txt" + id).show();
}

var bannerIdx = 0;
var bannerCount = 0;
var timerCount = 0;

$.fn.delay = function(time, name) {
    return this.queue((name || 'fx'), function() {
        var self = this;
        setTimeout(function() { $.dequeue(self); } , time);
    });
};

function loadSlideShow(groupID) {
	$('a.slideshow-' + groupID).colorbox({
		slideshow: true,
		transition: 'elastic'
	});
}

function loadBanners() {
	bannerCount = $('#banners .banner').length;
	bannerIdx = 0;

	if (bannerCount > 1) {
		showBanner(+1);
	} else {
		$('#banners div.banner:eq(0)').fadeIn(300);
	}
}

function showBanner(increase) {
	$('#banners div.banner:eq(' + bannerIdx + ')').fadeOut(300);

	bannerIdx = (bannerIdx + increase + bannerCount) % bannerCount;

	$('#banners div.banner:eq(' + bannerIdx + ')').fadeIn(300, function() {
		timerCount++;
  		$.timer(10000, function() {
  			if(timerCount == 1) {
				showBanner(+1);
			}
			timerCount--;
		});
	});
}

function verifycontactform(btn) {
	btn.disabled = true;
	btn.value = 'Sending message now ...';
	var message = 'Please fill out: ';
	var isGood = true;
	var emailRegEx = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
	
	if ( $('#email').val() == "") {
		message = message + "\n -  Email";
		isGood = false;
	}
	if ( $('#message').val() == "") {
		message = message + "\n -  Message";
		isGood = false;
	}
	if (!$('#email').val().match(emailRegEx) ) {
		message = message + "\n -  Email";
		isGood = false;
	}                                       
	if (isGood) {
        new SendEmail(btn, 'Icelandic Mountain Guides - Contact', 'mountainguides@mountainguides.is', 2);
	} else {
		alert(message);
		btn.disabled = false;
		btn.value = 'Send';
	}

	return isGood;
}

function SetTourCurrency(isk, currID) {
    var newCurr = correct((Math.round((isk/cur[currID])*100))/100);
    $('.prate').text(newCurr);
    $('.prateisk').text(curN[currID]);
}
