$(document).ready(function()
{
	// If it's the frontpage, insert the flash over the menu
	if($('.frontpageflash').length)
	{
		insertFrontpageFlash();
	}

	// Menu Hover IE 6 
	if( $.browser.msie && $.browser.version < 7 )
		$('#menu ul.main li.menu_item').hover(function(){ $(this).addClass('hover').find('ul.submenu').height(50); },function(){ $(this).removeClass('hover'); });

	// Striped tables
	$("table.productinformation tbody tr:even").css("background-color", "#fff");
	$("table.productinformation tbody tr:odd").css("background-color", "#f4f4f4");

	// Add css class 'www' to offsite links
//	$("a[href^=http]:not(:has(img))").addClass('www');

	//Adds Google Event tracking info to links w/the PDF CLASS
	$("#contentpage .pdf").each(function() { 
		var TITLE = this.title; 
		$(this).attr("onclick","pageTracker._trackEvent('PDF', 'Downloads', '"+ TITLE +"');");
	}); 

	//Adds Google Event tracking info to links w/the CATALOGPAGE CLASS
	$("#contentpage .catalogpage").each(function() { 
		var TITLE = this.title; 
		$(this).attr("onclick","pageTracker._trackEvent('PDF', 'Downloads', '"+ TITLE +"');");
	}); 



	$("#ProductLineBox ").click(function(){
		$(this).toggleClass("active")

	});

	// Add css class 'email' to email links
//	$("a[href^=mailto]").addClass('email');

	// Add Event tracking to links with css selector PDF
//	$('a.pdf').click(function() {
//		var $a = $(this);
//	  var title = $a.attr('title');	
//	  customLink = 'PDF', 'Download', this.title)';
//	  pageTracker._trackEvent(customLink);
//	});

	// front page slider
	$("#slider").easySlider({
		prevText: 'Previous',
		nextText: 'Next',		
		firstShow: false,
		lastShow: false,
		vertical: false, 
		continuous: false 		
	});

	$(".easyslider:first").easySlider({
		//auto: true,
		//continuous: true,
		//speed: 3000,
		prevId: 'prevBtn2',
		nextId: 'nextBtn2',
		lastId: 'lastBtn2',
		controlsShow: true
	});

	$(".easyslider:not(:first)").easySlider({
		prevId: 'prevBtn3',
		nextId: 'nextBtn3',
		lastId: 'lastBtn3',
		lastText: 'Last'
	});			

	//Ossurslider - edited easySlider by SBA

	$(".ossurslider:first").ossurSlider({
		prevClass: 'prev-button-first',
		nextClass: 'next-button-first',
		lastClass: 'last-button-first',
		navigationClass:	'slidernavigation',
		controlsShow: true,
		continuous: false 
	});
		
	
	$(".ossurslider:last").ossurSlider({
		prevClass: 'prev-button-last',
		nextClass: 'next-button-last',
		lastClass: 'last-button-last',
		navigationClass:	'slidernavigation',
		controlsShow: true
	});	

	$(".ossurslider2:first").ossurSlider({
		prevClass: 'prev-button-first2',
		nextClass: 'next-button-first2',
		lastClass: 'last-button-first2',
		navigationClass:	'slidernavigation',
		controlsShow: true
	});
		
	$(".ossurslider2:last").ossurSlider({
		prevClass: 'prev-button-last2',
		nextClass: 'next-button-last2',
		lastClass: 'last-button-last2',
		navigationClass:	'slidernavigation',
		controlsShow: true
	});	

	//Image-fader - with links (for possible values see comments in jquery.js) used for fading images in slideshows e.g. on Bionics page Corporate

	$('.fade').innerfade({
		speed: 1000,
		timeout: 5000,
		type: 'sequence',
		containerheight: '80px'
	});

	$('.fade-frontpage').innerfade({
		speed: 1000,
		timeout: 5000,
		type: 'sequence',
		containerheight: '295px'
	});	


	// accordion menu
	$(".accordion h3:first").addClass("active");
	$(".accordion div.answer:not(:first)").hide();

	$(".accordion h3").click(function(){
		$(this).next("div.answer").slideToggle("slow")
// Commenting this line out enables answers to maintain visible
//		.siblings("div.answer:visible").slideUp("slow");
		$(this).toggleClass("active");
		$(this).siblings("h3").removeClass("active");
	});

	// impact level explanation hover text
//	$(".impact_levels a").append("<em></em>");
//	
//	$(".impact_levels a").hover(function() {
//		$(this).find("em").animate({opacity: "show", top: "-115"}, "slow");
//		var hoverText = $(this).attr("rel");
//	    $(this).find("em").text(hoverText);
//	}, function() {
//		$(this).find("em").animate({opacity: "hide", top: "-115"}, "fast");
//	});


	// Support of old flash "WriteFlash" variable



	// dictionary hover text ERROR - Unexpected token

	$(".dictionary").append("<em></em>");

	$(".dictionary").hover(function() {
	  $(this).find("em").animate({opacity: "show"}, "slow");
	  var hoverText = $(this).attr("longdescr");
	  $(this).find("em").text(hoverText);
	}, function() {
	  $(this).find("em").animate({opacity: "hide"}, "slow");
	});

	// Sortable tables (used for IFU download) - commented out as it disrupted the shadow-box function.
	//	$("#sortable").tablesorter({
	//	sortList: [[0,0], [1,0]]		
	//	});

	// persist fontsize
	if($.cookie('fontSizeChange') && $.cookie('fontSizeChange') !== '0')
	{
		$.fontSize({ change: Number($.cookie('fontSizeChange')) });
	}

	//Shadowbox video player app
	// Define basic Shadowbox options for using the image player.
	var sbOptions = {
		handleOversize: 'none',
		animate: true,
		displayNav: true,
		handleUnsupported: 'remove',
		initialHeight: 60,
		initialWidth: 100
	};
	Shadowbox.init(sbOptions);

	//Show/hide for left menu
	$('#LeftNavigationMenu span.arrow').click(function()
	{
		$(this).parent().toggleClass('down');
		$(this).parent().toggleClass('hidden-children');
		return false;
	});
});

function WriteFlash(movie, width, height)
{
	var flash = '<object codeBase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" height="' + height + '" width="' + width + '" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">';
	flash += '<param name="Movie" value="' + movie + '">';
	flash += '<embed src="' + movie + '" quality="high" bgcolor="" height="' + height + '" width="' + width + '" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">';
	flash += '</embed>';
	flash += '</object>';
	document.write(flash);
}

function lisa_flash(s,w,h)
{
	var a=arguments
	with(document)
	{
		writeln('<object codeBase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" height="'+h+'" width="'+w+'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="asdf">')
		writeln('<param name="Movie" value="'+s+'">')
		for(var i=3;i<a.length;i+=2)writeln('<param name="'+a[i]+'" value="'+a[i+1]+'">')
		write('<embed src="'+s+'" quality="high" height="'+h+'" width="'+w+'" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" ')
		for(i=3;i<a.length;i+=2)write(a[i]+'="'+a[i+1]+'" ')
		writeln('/>')
		write('</object>')
	}

}

// Inserts flash on the frontpage, if JS is disabled or the user doesn't have the correct flash version, the plain HTML menu will stay put
function insertFrontpageFlash()
{
	var flashvars = 
		{  
		};
	var params = 
		{  
			wmode: "transparent"
		};
	var attributes = 
		{  
		};
		swfobject.embedSWF("/lisalib/getfile.aspx?itemid=16950", "flash-frontpage-replacer", "970", "335", "9.0.0","/lisalib/getfile.aspx?itemid=14596", flashvars, params, attributes);
}

function ToggleDiv(divName)
{
	if (document.getElementById(divName).style.display != 'block')
	{ // DOM3 = IE5, NS6
		document.getElementById(divName).style.display = 'block';
	}
	else
	{
		document.getElementById(divName).style.display = 'none';
	}
}


function setState(val)
{
	var options = document.getElementById('state').getElementsByTagName('option');

	if(cities.indexOf(val) != -1)
	{
		var stopt = states[cities.indexOf(val)];

		for(var i = options.length - 1; i >= 0; i--)
		{
			if(stopt.indexOf(options[i].value) != -1)
			{
				options[i].style.display = 'block';
				document.getElementById('state').selectedIndex = i;
			}
			else
			{
				options[i].style.display = 'none';
			}
		}
	}
	else
	{
		for(var i = 0; i < options.length; i++)
		{
			options[i].style.display = 'block';
		}
	}
}

var formValidationPostfix = " was not properly filled out!";

function validate(form) {
	var isValid = true;
	for (var i = 0; i < form.elements.length; i++) {
		var elem = form.elements[i];
		if (elem.className.indexOf('reqd') > 0 || elem.className.indexOf('email') > 0) {
			
			/* input, select og textarea er höndlað á sama hátt .... */
			if ((elem.tagName == "INPUT") || (elem.tagName == "TEXTAREA") || (elem.tagName == "SELECT")) {			
				if (elem.className.indexOf('emailval') > 0) {
					isValid = isValidEmail(elem.value);
				} else {
					isValid = (elem.value != '');
				}
				
				if (!isValid) {
					alert(elem.title + formValidationPostfix);
					elem.focus();
					elem.style.borderColor = '#FF4A4A';
					elem.style.backgroundColor = '#FDFAD0';
					return false;
				} else {
					elem.style.borderColor = '';
					elem.style.backgroundColor = '';
				}
			}			
		}
	}
	return true;
}

function isValidEmail(value) {
	return (value.indexOf(".") > 0) && (value.indexOf("@") > 0);
}

function isValidNumber(value, number) {
	var elemIsValid = true;
	var stripped = value.replace(/[\(\)\.\-\ ]/g, '');
	
	if (!(stripped.length == number)) {
		elemIsValid = false;
	}

	if(isNaN(stripped)) {
	     elemIsValid = false;
   	}

	if (stripped.length == 0) {
		elemIsValid = true;
	}
	
	return elemIsValid;
}

function bookmark()
{
	var url = document.location;
	var title = document.title;
	var e;

	if(window.external && typeof window.external.AddFavorite == "unknown")
	{
		try
		{
			window.external.AddFavorite(url, title);
		}
		catch(e) {}
	}
	else if(window.sidebar && typeof window.sidebar.addPanel == "function")
	{
		try
		{
			window.sidebar.addPanel(title, url, "");
		}
		catch(e) {}
	}
}

//Fall til að búa til köku, er meðal annars notað í Product Ideas Submission.
function createCookie(cookiename,cookievalue,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
		var expires = '; expires=' + date.toGMTString();
	}
	else var expires = '';
	document.cookie = cookiename + '=' + cookievalue + expires + '; path=/';
}