/* Author: 
	Eystein Mack Alnžs
	http://thatNorwegianGuy.com/
*/
$(document).ready( function() {
   
    // open external link in new tab/window
    $("a[href*='http://']:not([href*='"+location.hostname+"'])").click(function(){
      this.target = "_blank";
    });
       	
});

$(document).ready(function() {
	
	$('h2').addClass('js');
	$('h2.js').wrapInner('<div />');

	if($.browser.msie) {
		$('#main_nav ul.navigation li').hover(function(){
			$('ul', $(this)).css('left', 0);
		},function(){
			$('ul', $(this)).css('left', '-999em');
		});
		$('ul.navigation li:last-child a').css('borderRight', 'none');
	}

	$(".columns li").equalHeights();

	$(".search_form label").overlabel();
	$("#aside .vip_form label").overlabel();

	$('a.print').click(function() {
		self.print();
		return false;
	});

	$('#aside ul.navigation li').hover(function(){
		$(this).addClass('hover');
	}, function(){
		$(this).removeClass('hover');
	});

/* ######################################################## */	
/*	 			Slideshow with automatic start 				*/

	$('.slideshow').bxSlider({
		mode: 'horizontal',						// 'horizontal', 'vertical', 'fade'
		infiniteLoop: true,						// true, false - display first slide after last
		hideControlOnEnd: false,				// true, false - if true, will hide 'next' control on last slide and 'prev' control on first
		controls: true,							// true, false - previous and next controls
		speed: 1000,								// integer - in ms, duration of time slide transitions will occupy
		easing: 'swing',                    	// used with jquery.easing.1.3.js - see http://gsgd.co.uk/sandbox/jquery/easing/ for available options
		pager: true,							// true / false - display a pager
		pagerSelector: '#slide-counter',					// jQuery selector - element to contain the pager. ex: '#pager'
		pagerType: 'full',						// 'full', 'short' - if 'full' pager displays 1,2,3... if 'short' pager displays 1 / 4
		pagerLocation: 'bottom',				// 'bottom', 'top' - location of pager
//		pagerShortSeparator: '/',				// string - ex: 'of' pager would display 1 of 4
		pagerActiveClass: 'pager-active',		// string - classname attached to the active pager link
		nextText: 'next',						// string - text displayed for 'next' control
		nextImage: '',							// string - filepath of image used for 'next' control. ex: 'images/next.jpg'
		nextSelector: '#slide-direction',						// jQuery selector - element to contain the next control. ex: '#next'
		prevText: 'prev',						// string - text displayed for 'previous' control
		prevImage: '',							// string - filepath of image used for 'previous' control. ex: 'images/prev.jpg'
		prevSelector: '#slide-direction',						// jQuery selector - element to contain the previous control. ex: '#next'
//		captions: false,						// true, false - display image captions (reads the image 'title' tag)
//		captionsSelector: null,					// jQuery selector - element to contain the captions. ex: '#captions'
		auto: true,							// true, false - make slideshow change automatically
//		autoDirection: 'next',					// 'next', 'prev' - direction in which auto show will traverse
		autoControls: true,					// true, false - show 'start' and 'stop' controls for auto show
		autoControlsSelector: '#slide-on-off',				// jQuery selector - element to contain the auto controls. ex: '#auto-controls'
		autoStart: true,						// true, false - if false show will wait for 'start' control to activate
		autoHover: false,						// true, false - if true show will pause on mouseover
		autoDelay: 0,                       	// integer - in ms, the amount of time before starting the auto show
		pause: 30000,							// integer - in ms, the duration between each slide transition
		startText: 'START',						// string - text displayed for 'start' control
		startImage: '',							// string - filepath of image used for 'start' control. ex: 'images/start.jpg'
		stopText: 'STOP',						// string - text displayed for 'stop' control
		stopImage: '',							// string - filepath of image used for 'stop' control. ex: 'images/stop.jpg'
//		ticker: false,							// true, false - continuous motion ticker mode (think news ticker)
												// note: autoControls, autoControlsSelector, and autoHover apply to ticker!
//		tickerSpeed: 5000,						// float - use value between 1 and 5000 to determine ticker speed - the smaller the value the faster the ticker speed
//		tickerDirection: 'next',				// 'next', 'prev' - direction in which ticker show will traverse
//		tickerHover: false,                 	// true, false - if true ticker will pause on mouseover
		wrapperClass: 'bx-wrapper',				// string - classname attached to the slider wraper
		startingSlide: 0 						// integer - show will start on specified slide. note: slides are zero based!
//		displaySlideQty: 1,						// integer - number of slides to display at once
//		moveSlideQty: 1,						// integer - number of slides to move at once
//		randomStart: false	
	});
	
});
(function($) {
	var cache = [];
	// Arguments are image paths relative to the current page.
	$.preLoadImages = function() {
		var args_len = arguments.length;
		for (var i = args_len; i--;) {
		  var cacheImage = document.createElement('img');
		  cacheImage.src = arguments[i];
		  cache.push(cacheImage);
		}
	}
	$.parseJSON = function( data ) {
		var rvalidchars = /^[\],:{}\s]*$/;
		var	rvalidescape = /\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g;
		var rvalidtokens = /"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g;
		var rvalidbraces = /(?:^|:|,)(?:\s*\[)+/g;
		if ( typeof data !== "string" || !data ) {
			return null;
		}

		// Make sure leading/trailing whitespace is removed (IE can't handle it)
		data = jQuery.trim( data );
		
		// Make sure the incoming data is actual JSON
		// Logic borrowed from http://json.org/json2.js
		if ( rvalidchars.test(data.replace(rvalidescape, "@")
			.replace(rvalidtokens, "]")
			.replace(rvalidbraces, "")) ) {

			// Try to use the native JSON parser first
			return window.JSON && window.JSON.parse ?
				window.JSON.parse( data ) :
				(new Function("return " + data))();

		} else {
			jQuery.error( "Invalid JSON: " + data );
		}
	}

})(jQuery)

