

       

$(function(){

	var LoadMsg = 'Laster innhold ...';
	
	//var FlashHtml  = $('#flash').html();
	var FlashHtml = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="950" height="300"><param name="movie" value="flash/vmk-main.swf"><param name="quality" value="high"><param name="wmode" value="transparent"><embed wmode="transparent" src="flash/vmk-main.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="950" height="300"></object>';

var FlashHtmlPre  = $('#flash').html();
	$('#navigasjon a').click(function(){
		 
		/*$('#flash2').html('<img id="fpic" name="fpic" src="grafikk/Sider/Flashreplacement/' + $(this).attr('id') + '.jpg">');

		$('#flash2 img').each(function() {
									  
	        var maxWidth = 100; // Max width for the image
	        var maxHeight = 100;    // Max height for the image
	        var ratio = 0;  // Used for aspect ratio
	        var width = $(this).width();    // Current image width
	        var height = $(this).height();  // Current image height
	        //alert('imgs: ' + width);
	        if (width < 50)
	        {
				
				if(FlashHtmlPre != FlashHtml){
					
					$('#flash').html(FlashHtml);
				}
	        }else{
				$('#flash').html($('#flash2').html);
				$('#flash2').html('');
			}
		});*/
		var i = 0;
		
		
		
		$('#flash2').html('<img id="fpic" name="fpic" src="grafikk/Sider/Flashreplacement/' + $(this).attr('id') + '.jpg">');
			
										  
			$('#flash2 img').each(function() {
				var maxWidth = 100; // Max width for the image
				var maxHeight = 100;    // Max height for the image
				var ratio = 0;  // Used for aspect ratio
				var width = $(this).width();    // Current image width
				var height = $(this).height();  // Current image height
				//alert('imgs: ' + width);
				if (width < 50)
				{
					if($('#flash').html().length < 500)
					{
						$('#flash').html(FlashHtml);
					}
					//$('#flash').html(FlashHtml);
				}else{
					$('#flash').html($('#flash2').html);
					i+=1;
				}
				
			});
			
			/*if(i>0)
			{
				$('#flash').html($('#flash2').html);
				
			}else{
				//alert($('#flash2').html());
				
			}*/
			$('#flash2').html('');

		//if(!$(this).hasClass("active")) {
			
			var _Href = $(this).attr('href');
			var page = _Href.substring(15, _Href.indexOf("&"));
			//alert('page: '  + page);
			$('#navigasjon a').removeClass("active");
			// alt inactive
			//var src = $('img#hom').attr('src').replace('/active', '/inactive');
			//$('img#hom').attr("src", src);
			//src = $('img#snoskuter').attr('src').replace('/active', '/inactive');
			//$('img#snoskuter').attr("src", src);
			//src = $('img#' + $(this).attr('id')).attr('src').replace("inactive", "active");
			//							$('img#' + $(this).attr('id')).attr("src", src);
			//sett alle inacive...
			$("#navigasjon img").each(function() {
			   // $(this).wrap('<div></div>');
			    var src = $(this).attr('src').replace('/active-', '/inactive-');
			    $(this).attr("src", src);
			    src = $(this).attr('src').replace('/over-', '/inactive-');
			    $(this).attr("src", src);
			});

			// sett knapp aktiv
			var src = $('img#' + $(this).attr('id')).attr('src').replace("/inactive-", "/active-");
	
			//alert('test');
			$('img#' + $(this).attr('id')).attr("src", src);

			$("#navigasjon a").each(function() {
		    	var link = $(this);
		    	var image = $(link).children("img");  
		   		var imgsrc = $(image).attr("src");

				$(link).mouseover(function(){  
						var on = imgsrc.replace('/inactive-', '/over-');  
						$(image).attr("src",on); 
	
				});          

				 $(link).mouseout(function(){  
						$(image).attr("src",imgsrc);  
				});  

			});


			// sett hover 
			//var rep  = $('#navigasjon').html().replace("inactive-"+page, "active"+page);
			//alert (rep);
			$(this).addClass("active");
			//alert($(this).attr('id'));
			$('<div id="loading"></div>').appendTo('body').fadeIn('slow',function(){
				$.ajax({
					type:	'POST',
					url:	_Href,
					data:	"ajax=1",
					dataType:	'html',
					timeout:	5000,
					success: function(d,s){
						$('#loading').fadeOut('slow',function(){
							$(this).remove();			
							$('#innhold').slideUp('slow',function(){
								$(this).html(d).slideDown('slow');
							});

						});
					},
					error: function(o,s,e){
						$('#loading').html('Ajax Request Failed: '+s);
						eTimer(_Href);
					}
				});
			});
		//}
		return false;
	});

	


	function eTimer(url) {

		var t=setTimeout("window.location='"+url+"'",1000);

		$('#loading').fadeOut('slow');

	}

});




