﻿
var movieplayer = null;

function play_movie()
{

		if($('#videoFrame').length == 0)
		{
			$(document.body).prepend('<div id="videoFrame"><div id="videoFrameBg">&#160;</div></div>');
		}

		$('#videoFrameBg').fadeTo(500, 0.6, function()
		{


		});


			document.getElementById("video").style.display ="inline";	
			
			var scrollTop = document.body.scrollTop;
			if (scrollTop == 0)
			{
				if (window.pageYOffset)
					scrollTop = window.pageYOffset;
				else
					scrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
			}
			
			if(movieplayer != null)
			{
				movieplayer.load();
				movieplayer.play();		
			}


}

function close_movie()
{
	if(movieplayer != null)
	{
		movieplayer.unload();
	}
	document.getElementById("video").style.display="none";

	$(document.getElementById('videoFrameBg')).fadeOut(500, function() {
		$(document.getElementById('videoFrame')).remove();
	});
}

function on_load()
{
	if(flashembed.isSupported([9, 0]))
	{
		
		movieplayer = $f("flowplayer_player", "/swf/flowplayer-3.2.5.swf", { 
			clip: { 
				// when this is false playback does not start until play button is pressed 
				autoPlay: false 
			}  
		});   
	}
	else
	{
		document.getElementById("video_window").style.textAlign = "center";
		var player = document.getElementById("flowplayer_player");
		
		player.href = "http://www.adobe.com/go/getflashplayer";
		player.innerHTML = "Download Adobe® Flash™ Player.";
		player.style.display="inline";
		player.style.position = "relative";

		
	}
}


/* SHORTCUT RIGHT */

function setText(a, b) {
    x = document.getElementById(a);
    if (x)
        x.innerHTML = b.options[b.selectedIndex].innerHTML;
}


	function checkLoginCookie(path)
	{

		var randomnumber=Math.floor(Math.random()*11)

		// fjern randomnumber før live
		//var cookieName = 'myCookie8' + randomnumber;
		var cookieName = 'undersokelse2';

		if(getCookie(cookieName) == null)
		{
			//location.href='http://sbm.cust.avento.no/default.aspx?menu=326';
			//navigateTo('http://sbm.cust2.avento.no/app_form_public_edit.aspx?app_id=240&app=240&response=1&body=0&view=nettbank','_blank');
			navigateTo('/app_form_public_edit.aspx?app_id=252&app=252&response=1&body=0&view=nettbank','_blank');
		}
		else
		{
			navigateTo(path,'_blank');
		}

		var exp = new Date();     //set new date object
		exp.setTime(exp.getTime() + (1000 * 60 * 60 * 24 * 30));     //set it 30 days ahead 

		setCookie(cookieName,'Nettbank', exp);
	}



	function setCookie(name, value, expires) {
		document.cookie = name + "=" + escape(value) + "; path=/" + ((expires == null) ? "" : "; expires=" + expires.toGMTString());
	} 

	function getCookie (name) {
		
		var dc = document.cookie;
		var cname = name + "=";

		if (dc.length > 0) {
		  begin = dc.indexOf(cname);
		  if (begin != -1) {
			begin += cname.length;
			end = dc.indexOf(";", begin);
			if (end == -1) end = dc.length;
			return unescape(dc.substring(begin, end));
			}
		  }
		return null;
	}


	function shortcutOpen(nId)
	{
		//alert("div_shortcut_right_" + nId);

		var nTime = 300;
		if (document.getElementById("curShortcutRight").value != "")
		{
			shortcutClose(document.getElementById("curShortcutRight").value);
		}

		document.getElementById("curShortcutRight").value = nId;

		var b = document.getElementById("div_shortcut_right_" + nId);
		var a = document.getElementById("div_shortcut_cat_" + nId);
		var fade = $('#div_img_fade_' + nId);
		// if the element is currently being animated (to a fadeOut)...    
		if (fade.is(':animated')) 
		{      
			// ...take it's current opacity back up to 1      
			fade.stop().fadeTo(nTime, 1);    
		} 
		else 
		{      
			// fade in quickly
			fade.fadeIn(nTime);

			
		}
		
		$(a).show(nTime);
		//b.onclick = function (){shortcutClose(nId);};
		b.onclick = function (){clickOpen(nId);};
		$(b).removeClass('clickable');
	}


	function shortcutClose(nId)
	{		

		if (document.getElementById("curShortcutRight").value == nId)
		{
			document.getElementById("curShortcutRight").value = "";
		}

		var nTime = 300;
		var b = document.getElementById("div_shortcut_right_" + nId);
		var a = document.getElementById("div_shortcut_cat_" + nId);
		var fade = $('#div_img_fade_' + nId);
		if (fade.is(':animated')) 
		{
			fade.stop().fadeTo(nTime, 0);    
		} 
		else 
		{      
			// fade away     
			fade.fadeOut(nTime);
			

		}
		
		$(a).hide(nTime);
		b.onclick = function (){shortcutOpen(nId);};
		$(b).addClass('clickable');
		
	}
/* END SHORTCUT RIGHT */


/* LANGUAGE SELECTION */
	function languageSelectionOver(a,nFadeTime)
	{
		var fade = $('div[id^=div_img_]', a); 
		
		//alert(fade.className);
		if (fade.is(':animated')) 
		{
			fade.stop().fadeTo(nFadeTime, 1);
			//fade.stop();
			fade.fadeIn(nFadeTime);
		} 
		else 
		{      
			fade.fadeIn(nFadeTime);
		}
	}

	function languageSelectionOut(a,nFadeTime)
	{
		var fade = $('div[id^=div_img_]', a); 
		
		//alert(fade.className);
		if (fade.is(':animated')) 
		{         
			fade.stop().fadeTo(nFadeTime, 1);
			//fade.stop();
			fade.fadeOut(nFadeTime);
		} 
		else 
		{      
			fade.fadeOut(nFadeTime);
		}		
	}
/* END LANGUAGE SELECTION */

/* communication field */


	function flashOpen(flashFile, flashHeight)
	{
		if (!document.getElementById("modalflashvideo") || document.getElementById("modalflashvideo") ==
		null || document.getElementById("modalflashvideo") == "undefined")
		{
		}
		else
		{


			$("#modal").fadeIn(500, function () {
				var flashfile = "swf/playFLV.swf";
				var att = { data: flashfile, width: "950", height: flashHeight };
				var par = { wmode: "transparent", allowFullScreen: "false", flashvars: "dataSource=swf/slideshow_xml.aspx?object_id=" + flashFile };
				var id = "modalflashvideo";
				var myObject = swfobject.createSWF(att, par, id);
				$("#modalflashvideo").show();
			});

		}
	}

	function flashOpen2(flashFile)
	{

		if (!$("#loader").is(':animated') && !$("#flashslideshow_outer").is(':animated'))
		{
			// video
			if (!document.getElementById("flashvideo") || document.getElementById("flashvideo") ==
			null || document.getElementById("flashvideo") == "undefined")
			{
			}
			else
			{
				document.getElementById('video_div').style.display = 'block';

				var flashfile = "swf/playFLV.swf";
				var att = { data: flashfile, width: "693", height: "292" };
				var par = { wmode: "transparent", allowFullScreen: "true", flashvars: "dataSource=swf/slideshow_xml.aspx?object_id=" + flashFile };
				var id = "flashvideo";
				var myObject = swfobject.createSWF(att, par, id);

				$("#flashvideo_outer").css({visibility: "hidden"});
				$("#flashvideo_outer").css({zIndex: "1000"});
				$("#flashvideo_outer").css({display: "block"});

				$("#loader").fadeTo(500, 1, function(){
					
					$("#flashvideo_outer").css({visibility: "visible"});

					$("#flashslideshow_outer").animate({height: "296", marginBottom: "31"});
					$('#supersize_links_inner').stop().animate({bottom: "27px"});


					

					$("#loader").fadeTo(500, 0, function(){
						$("#loader").css({display: "none"});
						
					});
				
				});

			}
		}
	}

	function flashClose()
	{
		// $("#modalflashvideo").style.display = 'none';

		document.getElementById('modalflashvideo').style.display = 'none';
		//document.getElementById('video_div').style.display = 'none';
		
		$("#modal").fadeOut(500);
	}

	function flashClose2()
	{
		if (!$("#loader").is(':animated') && !$("#flashslideshow_outer").is(':animated'))
		{

			//$("#flashslideshow").css({visibility: "visible"});
			//$("#flashslideshow_outer").css({visibility: "visible"});
			//$("#flashslideshow_outer").fadeTo(500, 1);

			$("#loader").fadeTo(500, 1, function(){
				//$("#flashslideshow_outer").stop().fadeTo(500, 1);
				
				//$("#flashslideshow_outer").css({overflow: "visible"});

				$("#flashslideshow_outer").animate({height: "327", marginBottom: "0"});

				$("#loader").fadeTo(500, 0, function(){$("#loader").css({display: "none"});});
				
				//document.getElementById('loader').style.opacity = '1';
				//$("#loader").fadeOut(1000);
				//$("#video_div").fadeOut(1000);
				$("#flashvideo_outer").css({display: "none"});
				
				//document.getElementById('flashvideo').style.display = 'none';
			});

		}
	}

	/* end communication field */





	$(document).ready
    (


	function () {


		$("a[href^='\#']").click(function(e){
			e.preventDefault();

			var UrlSubStringLength = document.URL.indexOf('#');

			if(UrlSubStringLength == -1)
			{
				UrlSubStringLength = document.URL.length;
			}

			document.location=document.URL.substr(0, UrlSubStringLength) + this.href.substr(this.href.indexOf('#'));
		 })

	    // form more info
	    tooltip();

	    // change input css
	    $('input[type=text]').addClass('input_text');
	    $('input[type=button]').addClass('input_button clickable');

	    // nettbank input text
	    $('input[type=button]').hover(
		function () {
		    this.setAttribute("class", "input_button_hover clickable");
		}
		, function () {
		    this.setAttribute("class", "input_button clickable");
		}
		);

	    // fade in language selection
	    if (!document.getElementById("div_language_selection_" + document.getElementById("curSiteLang")) || document.getElementById("div_language_selection_" + document.getElementById("curSiteLang")) ==
		null || document.getElementById("div_language_selection_" + document.getElementById("curSiteLang")) == "undefined")
	    { }
	    else {
	        languageSelectionOver(document.getElementById("div_language_selection_" + document.getElementById("curSiteLang").value), 1);
	    }

	    // tab selection
	    if (!document.getElementById("curFane") || document.getElementById("curFane") ==
		null || document.getElementById("curFane") == "undefined")
	    { }
	    else {
	        //alert(document.getElementById("curFane").value);
	        // fade in fane selection
	        languageSelectionOver(document.getElementById("div_fane_selection_" + document.getElementById("curFane").value), 1);

	        //alert("her");
	        //$('#div_fane_' + document.getElementById("curFane").value).show(1);
	    }

	    $('.div_shortcuts_right').hover(
			function () {
			    if (this.id != "div_shortcut_right_" + document.getElementById("curShortcutRight").value || this.id == "div_shortcut_right_") {
			        var nTime = 150;

			        var fade = $(this).find('.div_img_fade');



			        // if the element is currently being animated (to a fadeOut)...    
			        if (fade.is(':animated')) {
			            // ...take it's current opacity back up to 1      
			            fade.stop().fadeTo(nTime, 1);
			        }
			        else {
			            // fade in quickly
			            fade.stop().fadeTo(nTime, 1);
			            //fade.fadeIn(nTime);
			        }


			    }

			}
		, function () {
		    if (this.id != "div_shortcut_right_" + document.getElementById("curShortcutRight").value || this.id == "div_shortcut_right_") {
		        var nTime = 150;

		        var fade = $(this).find('.div_img_fade');
		        if (fade.is(':animated')) {
		            fade.stop().fadeTo(nTime, 0);
		        }
		        else {
		            // fade away
		            fade.stop().fadeTo(nTime, 0);
		            //fade.fadeOut(nTime);
		        }
		    }
		}
		);

	    // nettbank input text
	    $('#input_logg_inn').hover(
		function () {
		    if (this.value == "Nettbank brukernavn") {
		        this.value = "";
		    }

		    $('#input_logg_inn').removeClass('input_gray_text');
		}
		, function () {
		    if (this.value == "") {
		        this.value = "Nettbank brukernavn";
		    }
		    if (this.value == "Nettbank brukernavn") {
		        $('#input_logg_inn').addClass('input_gray_text');
		    }

		}
		);


	    // on menu top hover and menu has shortcuts
	    $('.menu_top_li_scroll').hover(
		function () {
		    $(this).css({ background: "url('../images/design/1_fane_hel.gif') no-repeat left top" });
		    $('.div_menu_top', this).css({ background: "url('../images/design/1_fane_hoyre3.gif') no-repeat right top" });

		    $('.menu_top_li_sel').css({ background: "url('../images/design/1_fane_hel2.gif') no-repeat left top" });
		    $('.div_menu_top_sel').css({ background: "url('../images/design/1_fane_hoyre4.gif') no-repeat right top" });

		}
		, function () {
		    $(this).css({ background: "none" });
		    $('.div_menu_top', this).css({ background: "none" });

		    $('.menu_top_li_sel').css({ background: "url('../images/design/1_fane_hel.gif') no-repeat" });
		    $('.div_menu_top_sel').css({ background: "url('../images/design/1_fane_hoyre3.gif') no-repeat right top" });


		}
		);

	    // on menu top hover and menu has shortcuts
	    $('.menu_top_scroll').hover(
		function () {
		    var nTime = 400;

		    // on hovering over, find the element we want to fade *up*    
		    var scroll = $('> div', this);
		    // if the element is currently being animated (to a fadeOut)...    
		    if (scroll.is(':animated')) {
		        //scroll.stop().animate({ height: "237px" }, nTime);
		        scroll.stop().animate({ height: "262px" }, nTime);

		        //backgroundPosition:left -40px;
		    }
		    else {
		        // scroll in quickly				
		        scroll.animate({ height: "262px" }, nTime);
		    }

		}
		, function () {
		    var nTime = 300;

		    // on hovering out, fade the element out    
		    var scroll = $('> div', this);
		    if (scroll.is(':animated')) {
		        scroll.stop().animate({ height: "0px" }, nTime);
		    }
		    else {
		        // scroll away slowly  
		        scroll.animate({ height: "0px" }, nTime);
		    }

		}
		);

	    // on language selection
	    $('.div_language_selection').hover(
		function () {
		    var a = document.getElementById("div_language_selection_" + document.getElementById("curSiteLang").value);
		    if (a != this) {
		        languageSelectionOver(this, 200);
		    }
		}
		, function () {
		    var a = document.getElementById("div_language_selection_" + document.getElementById("curSiteLang").value);
		    if (a != this) {
		        languageSelectionOut(this, 200);
		    }
		}
		);
	}
);




this.tooltip = function(){	
	/* CONFIG */		
		xOffset = 10;
		yOffset = 20;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$("a.tooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$("a.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};


