/* 
---------------------------------------------------
|	Produced by Webbfabriken.com (Robert Ikenberg)
|	for Alfons Åberg 2009-2010
|	Version 0.6b	
|	CMS 1.1 secure 4096
|	Latest branch 2010-03-08
|	
---------------------------------------------------
*/
	  var saveRandomNumber=0; 
	  var bgImageTotal=6;
	  var imagepath = "/LAYOUT/THEME/ALFONS/IMAGES/header-random/random";
	  randomPicEnd="a_125.gif";

	$jq(document).ready(function(){
	  doPingClient();
	  $jq(function() {
		  $jq("ul#menu span").css("opacity","0");
		  $jq("ul#menu span").hover(function () {
			  $jq(this).stop().animate({
				  opacity: 1
			  }, 'fast');
		  },
		  function () {
			  $jq(this).stop().animate({
				  opacity: 0
			  }, 'fast');
		  });
	  });


	  $jq(function() {
		  $jq(".flaggor span").css("opacity","0");
		  $jq(".flaggor span").hover(function () {
			  $jq(this).stop().animate({
				  opacity: 1
			  }, 'fast');
		  },
		  function () {
			  $jq(this).stop().animate({
				  opacity: 0
			  }, 'fast');
		  });
	  });

	  $jq(function() {
		  $jq(".copyright span").css("opacity","0");
		  $jq(".copyright span").hover(function () {
			  $jq(this).stop().animate({
				  opacity: 1
			  }, 'fast');
		  },
		  function () {
			  $jq(this).stop().animate({
				  opacity: 0
			  }, 'fast');
		  });
	  });

//	  $jq('div.corners').corner();//corner("effect corners width")
	  $jq('.corners').corner({
			  tl: { radius: 10 },
			  tr: { radius: 10 },
			  bl: { radius: 10 },
			  br: { radius: 10 }});

	  
	  $jq("div.alfie-start").mouseover(function ()
		{
		  $jq(this).addClass("alfie-hovered");
		});
	  
	  $jq("div.alfie-start").mouseout(function ()
		{
		  $jq(this).removeClass("alfie-hovered");
		});
	  $jq("div.alfie-start").click(function(){ 	  window.location="/"; return false;	});

	  $jq("button.button").mouseover(function ()
		{
		  $jq(this).addClass("button-hovered");
		});
	  
	  $jq("button.button").mouseout(function ()
		{
		  $jq(this).removeClass("button-hovered");
		});

	  var MyAjaxOptions = {target:'#function-response-text',success:showMyAjaxResponse};
		$jq('#myAjax-form').submit(function() { 
			$jq(this).ajaxSubmit(MyAjaxOptions); 
			return false; 
		}); 

	
	  var AsyncAjaxOptions = {target:'#function-response-text',success:showMyAjaxResponse};

	$jq(".form-validate").validate({
		submitHandler: function(form) {
		$jq('.ajax-form').submit(function() { 
			$jq(this).ajaxSubmit(AsyncAjaxOptions); 
			return false; 
		}); 
	   }
	})

	});

/* Application loaded functions */

	function showMyAjaxResponse(responseText, statusText)  { 
		var aResponseText = responseText.split(":");
		var v1=aResponseText[0]; //status
		var v2=aResponseText[1]; //värde1
		var v3=aResponseText[2]; //värde2
		var v4=aResponseText[3]; //värde2
		if (v1=="FUNCTION") {
			$jq("#function-response-text").html(v3);
			if (v2=="GOBACK") { $jq("#function-response-text").html(v3); }
			$jq('#function-response-text').show("slow"); 
		}
		else if (v1=="SUCCESS") {
			$jq("#function-response-text").html(v2);
			$jq('#function-response-text').show("slow"); 
		}
		else
		{ 

		$jq("#function-response-text").html(v1);
		$jq('#function-response-text').show("slow"); 
		}
	} 

/* ------------------------------------------------------------
 * POPUP WINDOW: GLOBAL VARIABLE(S)
 * ------------------------------------------------------------ */

var POPWIN  = null;

/* ------------------------------------------------------------
 * POPUP WINDOW: CLOSE EXISTING POPUP WINDOW
 * ------------------------------------------------------------ */

function closePopWin(theWin) {
  if ((theWin != null) && (theWin.closed != true))
  	theWin.close();
	}

/* ------------------------------------------------------------
 * POPUP WINDOW: DISPLAY POPUP WINDOW
 * ------------------------------------------------------------ */

function popWindow(loc,w,h) {

  	//closePopWin(POPWIN);	// closes an existing popup window if user opens 
                				// new window before closing existing window
	if (!(w)) var winW = screen.width - 100;
	else      var winW = w + 20;
	if (!(h)) var winH = screen.height - 150; 
	else      var winH = h + 20;
		
	var params  = "width=" + winW + ",height=" + winH + ",status=yes,toolbar=no,directories=no,scrollbars=yes,resizable=yes,menubar=no,location=no,top=50,left=50,screeny=50,screenx=50";
	POPWIN = window.open(loc,'MovieWindow',params);
	POPWIN.focus;
	}



function doPingClient() {
	appRandomPics();
	pingID=setTimeout(doPingClient,40000);
}

function appRandomPics() {
  try {
	var randomNumber = Math.round(Math.random()*(bgImageTotal-1))+1;
	if (randomNumber==saveRandomNumber) { randomNumber = Math.round(Math.random()*(bgImageTotal-1))+1; };
	imgPath=(imagepath+randomNumber+randomPicEnd);
	$jq('#AlfonsExtraRight').css('background-image', ('url("'+imgPath+'")'));
	saveRandomNumber=randomNumber;
  } catch(e) { }
}


