function skapaflash(DivID, ObjectID, WIDTH, HEIGHT, URL)
{
  var obj = document.getElementById(DivID);
  obj.innerHTML += "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0' id='" + ObjectID + "' width='" + WIDTH + "' height='" + HEIGHT + "' align='middle'><param name='allowScriptAccess' value='sameDomain' /><param name='movie' value='" + URL + "' /><param name='quality' value='high' /><param name='wmode' value='transparent' /><param name='bgcolor' value='#282828' /><embed src='" + URL + "' quality='high' wmode='transparent' bgcolor='#282828' width='" + WIDTH + "' height='" + HEIGHT + "' swLiveConnect='true' id='" + ObjectID + "' name='" + ObjectID + "' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></object>";
}

$(document).ready(function(){ 
       init();
Cufon.replace('h1, h2', { fontFamily: 'Bebas Neue', ignoreClass:'nocufon', hover:true });
});



this.imagePreview = function(){	
	/* CONFIG */
		
		xOffset = -10;
		yOffset = -240;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("a.preview").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br />" + this.t : "";
		$("body").append("<p id=\"preview\"><img src=\""+ this.href +"\" alt=\"Image preview\" class=\"previewimage\" />"+ c +"</p>");								 
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#preview").remove();
    });	
	$("a.preview").mousemove(function(e){
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};



(function($){
  $.fn.linkit = function() {
	this.each(function() {

		var mainUrl = $(this).parent().attr("href");
		$(this).parent().parent().parent().css("cursor","pointer");
		$(this).parent().parent().parent().click(function(){
			location.href=mainUrl;
		});
		
	});
  };
})( jQuery );



//VALIGN
(function($){
  $.fn.vAlign = function() {
	this.each(function() {

		imgheight = $(this).height();
		imgboxheight = $(this).parent().height();
		parentbox = $(this).parent();
		diff = parseInt((imgboxheight-imgheight)/2);
			if (diff > 5)
			{
			$(this).css("margin-top",diff + "px");
			}
	});
  };
})( jQuery );


function isValidEmailAddress(emailAddress) {
var pattern = new RegExp(/^[+a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/i);
return pattern.test(emailAddress);
};

function init()
{

$("#formtarget").submit(function(){
	var epost = $("#formtarget #newsletterepost").val();
	var valid = isValidEmailAddress(epost);
	var oldepost;
	if (valid == false)
	{
		$("#formtarget #newsletterepost").css({'border': '1px solid red'});
		oldepost = $("#formtarget #newsletterepost").val();
		$("#formtarget #newsletterepost").val('Ogiltig Epost-adress...');
		setTimeout("$(\"#formtarget #newsletterepost\").val('" + oldepost + "'); $(\"#formtarget #newsletterepost\").css({'border': '1px solid #c4c4c4'});",1500);
		return false;
	}
	else
	{
		return true;
	}

});

//tar bort klassen för h3 om script är aktiverat
$("h3").removeClass("noscripth3");

imagePreview();



$(".leftcontent").click(function(e){
	
	id = $(this).children(".submenu").attr('id');
});


$('#tabs div').hide(); // Hide all divs
	$('#tabs div:first').show(); // Show the first div
	$('#tabs ul li:first').addClass('active'); // Set the class of the first link to active
	$('#tabs ul li a').click(function(){ //When any link is clicked
	$('#tabs ul li').removeClass('active'); // Remove active class from all links
	$(this).parent().addClass('active'); //Set clicked link class to active
	var currentTab = $(this).attr('href'); // Set variable currentTab to value of href attribute of clicked link
	$('#tabs div').hide(); // Hide all divs
	$(currentTab).fadeIn(); // Show div with id equal to variable currentTab
	return false;
	});


$(".levinfo").hide();
$("#show_levinfo").click(function(){
		$(".levinfo").slideToggle('normal');
});


$(".preview").click(function(){

var url = $(this).attr("href");
var ww = $(window).width();
var wh = $(window).height();
var dh = $(document).height();
//lägger till objektet
var htmltag = "<div class=\"zoomimagebox\"></div><img class=\"zoomimage\" src=\"" + url + "\" alt=\"Zoom\" />";
$("body").append(htmltag);
$(".zoomimagebox").css("height",dh + "px");


//scroll top
var st = $(window).scrollTop();

//fixar positioneringen
var iw = (ww/2)-($(".zoomimage").width()/2);
var ih = (wh/2)-($(".zoomimage").height()/2);
$(".zoomimage").css("left",iw + "px");
$(".zoomimage").css("top",ih + st + "px");
$(".zoomimage").css("z-index", "1000");
$(".zoomimagebox").fadeIn(300,function(){
	$(".zoomimage").fadeIn();
});


$(".zoomimage").click(function(){
	$(".zoomimage").fadeOut();
	$(".zoomimagebox").fadeOut(450,function(){
	
		$('.zoomimage').remove();
		$('.zoomimagebox').remove();
	
	});
});

return false;
});



//fixar menyn
$(".submenu").hide();
$("*").removeClass('foldmenu');
$(".display_show").fadeIn();
$(".fold").attr('title','');
$(".fold").click(function(){
	var objectid = $(this).attr("id");
	var oid = objectid.substring(7, objectid.length);
	$("#menu" + oid + " .submenu").slideToggle('normal');
});




$('#nav li').hover(
		function () {
			//show its submenu
			$('ul', this).slideDown(400);

		}, 
		function () {
			//hide its submenu
			$('ul', this).slideUp(200);			
		}
	);


$(".leftcontent ul li a").hover(function(){
	$(this).animate({opacity: 0.7, marginLeft: '10'});
},function(){
	$(this).animate({opacity: 1, marginLeft: '5'});
});

$(window).load(function () {
$(".boxes .imgbox img").vAlign();
$(".readmore").linkit();
});


}
