jQuery(document).ready(function() {
	jQuery("img.a").hover(function() {
		jQuery(this).stop().animate(
		{
			"opacity": "0"
		}, "fast");
	}, function() {
		jQuery(this).stop().animate(
		{
			"opacity": "1"
		}, "slow");
	});
	jQuery(".clickable").click(function() {
		window.location = $(this).find("a").attr("href");
		return false;
	});
	
	jQuery(".accordion h3:first").addClass("active");
	jQuery(".accordion div:not(:first)").hide();
	jQuery(".accordion h3").click(function() {
		jQuery(this).next("div").slideToggle("slow").siblings("div:visible").slideUp("slow");
		jQuery(this).toggleClass("active");
		jQuery(this).siblings("h3").removeClass("active");
	});
	
	jQuery(window).load(function() {
		if (jQuery('#slider').length > 0) 
		{
			jQuery('#slider').nivoSlider(
			{
				effect: 'fold'
			});
		}
	});
	if (jQuery('.defaultDOMWindow') && jQuery('.defaultDOMWindow').openDOMWindow) 
	{
		jQuery('.defaultDOMWindow').openDOMWindow(
		{
			eventType: 'click',
			height: 600,
			width: 747,
			windowPadding: 0,
			overlayOpacity: '60',
			windowBGColor: 'transparent',
			borderSize: '0',
			positionType: 'centered'
		});
	}
	if (jQuery(".zoom") && jQuery(".zoom").fancybox) 
	{
		jQuery(".zoom").fancybox();
	}
	
	$(".paymentTabs").find(".tab").css("display", "none")
	
	var nr = 1;
	$(".paymentTabs").find("li").each(function() {
		li = $(this);
		if (li.hasClass("active")) 
		{
			$(".paymentTabs .tab:nth-child(" + nr + ")").css("display", "block");
			$(".paymentTabs li:nth-child(" + nr + ")").find("input").attr("checked", "checked")
		}
		li.addClass("tab_" + nr);
		li.bind("click", function() {
			me = $(this);
			$(".paymentTabs").find("li").removeClass("active");
			$(".paymentTabs").find(".tab").css("display", "none");
			$(".paymentTabs").find("li input").attr("checked", "")
			
			ex = me.attr("class").match(/tab_\d/).toString().split("_");
			$(".paymentTabs .tab:nth-child(" + ex[1] + ")").css("display", "block");
			$(".paymentTabs li:nth-child(" + ex[1] + ")").find("input").attr("checked", "checked")
			me.addClass("active");
		})
		nr++;
	})
});

/**
 * This functions is to debug variables.
 * NB! Only works with browsers that have a console, usualy firefox with firebug
 * @param {Mixed} value
 */
function debug(value) {

	if (typeof console == "object" && console && console.log) 
	{
		console.debug(value);
	}
	else 
	{
		//alert(value);
	}
}

/**
 * Function to round numbers
 * @param integer num -
 * @param integer dec - how many decimals after comma
 */
function roundNumber(number, dec) {
	var result = Math.round(number * Math.pow(10, dec)) / Math.pow(10, dec);
	return result;
}




/**
 * Finds whether a variable is a number or a numeric string
 *
 * @param {Mixed} value
 * @return {Boolean}
 */
function isNumeric(value) {
	if (value === null) 
	{
		return false;
	}
	if (value === undefined) 
	{
		return false;
	}
	if (value == "") 
	{
		return false;
	}
	value = value.toString().replace(/,/g, ".");
	if (isNaN(value) == true) 
	{
		return false;
	}
	else 
	{
		return true;
	}
}

/**
 * Finds whether a variable is a number or a numeric string
 *
 * @param {Mixed} value
 * @return {Boolean}
 */
function isNumber(value) {
	return isNumeric(value);
}


/**
 * Converts variable to numeric
 * @param {Mixed} v
 */
function toNumber(v) {
	if (v == undefined) 
	{
		return false;
	}
	v = v.toString().replace(/,/g, ".");
	if (isNumeric(v)) 
	{
		if (v.match(/\./)) 
		{
			return parseFloat(v);
		}
		else 
		{
			return parseInt(v);
		}
	}
	return 0;
}

/**
 * Converts number to positive number
 * @param {Object} nr
 * @return {number}
 */
function toPositive(nr) {
	if (nr != undefined) 
	{
		nr = nr.toString().replace("-", "")
		return toNumber(nr);
	}
	return "";
}

/**
 * Converts number to negative number
 * @param {Object} nr
 * @return {number}
 */
function toNegative(nr) {
	if (nr != undefined) 
	{
		nr = nr.toString().replace(/-/g, "")
		nr = '-' + nr;
		return toNumber(nr);
	}
	return "";
	
}

