/**
 *	Global functions
 *
 *	Developed for Greenflame
 *	October 2011
 *
 *	Version 1.0
 */
 
//-------------------------------------------------------------------


/**
 *	Run a bunch of functions on window.load
 *
 *	The reson this function is here is that you can only attach
 *	one events to window.load... at least so far i know :)
 */
$(window).load(function() {
	scaleGridItems();
	applyOrbitSlider();
	scaleFooter();
});


/*
 * Translater, changes ÆØÅ to UTF
 */
function translate(_str) {
	// æ and Æ
	_str = _str.replace(/æ/g,"ae");
	_str = _str.replace(/Æ/g,"Ae");
	_str = _str.replace(/%C3%A6/g,"ae");
	_str = _str.replace(/%C3%86/g,"Ae");
	
	// ø and Ø
	_str = _str.replace(/ø/g,"oe");
	_str = _str.replace(/Ø/g,"Oe");
	_str = _str.replace(/%C3%B8/g,"oe");
	_str = _str.replace(/%C3%98/g,"Oe");
	
	// å and Å
	_str = _str.replace(/å/g,"aa");
	_str = _str.replace(/Å/g,"Aa");
	_str = _str.replace(/%C3%A5/g,"aa");
	_str = _str.replace(/%C3%85/g,"Aa");
	
	// Return result
	return _str;
}


/*
 * Dropdown menu
 */
$(document).ready(function() {
	$("#dropdown").each(function() {
		$(this).children("ul").addClass("dropdown");
	});
	$(".dropdown li").each(function() {
		var _dir = $(this).children("ul").length;
		if(_dir > 0) {
			$(this).addClass("parrent");
			$(this).children("a").first().addClass("parrent");
		};
	});
});


/*
 * Apply image viewer (Fancybox)
 */
$(document).ready(function() {
	$("a[rel=group]").fancybox({
		'autoScale'		:	true,
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	true
	});
});


/*
 * Apply commercial rotator (Orbit or Nivo)
 */
function applyOrbitSlider() {
	_n = $('.bannere').children()	.size();
	if(_n > 1) {
		// Init orbit slider
		$('.orbit').orbit({
			bullets: true,
			timer: true,
			advanceSpeed: 8000,
			animation: 'horizontal-slide'
		});
		
	    $('.nivo').nivoSlider({
	        effect: 'sliceUpDown', // Specify sets like: 'fold,fade,sliceDown'
	        animSpeed: 500, // Slide transition speed
	        pauseTime: 8000, // How long each slide will show
	        startSlide: 0 // Set starting Slide (0 index)
	    });
    };
}


/*
 * Scale footer colums
 */
function scaleFooter() {
	var _siteWidth = Number($("#footer").outerWidth(true));
	var _blockAddWidth = Number(0);
	var _count = Number(0);
	$("#footer .block").each(function() {
		_blockAddWidth = _blockAddWidth + $(this).outerWidth(true);
		_count++
	});
	_blockAddWidth = (_siteWidth - _blockAddWidth) / _count;
	_blockAddWidth = Math.floor(_blockAddWidth);
	$("#footer .block").each(function() {
		var _objWidth = $(this).width() + _blockAddWidth;
		$(this).width(_objWidth)
	});
}

