// JavaScript Document

var gTimerSec;
	function fnTimeSec(){ // 1 sec interval, used for clock
		fnWingsOO(); // turn wings on and off based on the window width
	}
	
	var gTimerAni;
	function fnTimeAni(){ // 20 x second, used for animation
	
	}

// ##### beginning forms and radio
function fnBid(daID){return document.getElementById(daID);}

function fnBids(daID){return document.getElementById(daID).style;}

function fnOnChange (daID){
    var daAns = fnBid(daID).value;
    alert("10" + daAns);
    }


    var gPageHolderW,gLeftWingW,gRightWingW;
	var gLeftWingGap = 0;
	var gRightWingGap = 0;
	var gDoLeftWingOO=true;
	var gDoRightWingOO=true;
	
	function fnWingsOO(){
		// Get widths of window, wrapper, leftWing and rightWing ready for calculation
		gWinW = parseInt(fnBid('body').clientWidth);/*Get the width of Body*/
		gmiddleW = parseInt(fnBid('wrapper').clientWidth); /*Get the width of middle*/
		gLeftWingW = parseInt(fnBid('leftWing').clientWidth); /*Get the width of LeftWing*/
		gRightWingW = parseInt(fnBid('rightWing').clientWidth);  /*Get the width of RightWing*/ 
		// Calculations
		var vAnsL=gPageHolderW+(2*gLeftWingW);
		var vAnsR=gPageHolderW+(2*gRightWingW);
		
		
		// dLeftWing
		if(gDoLeftWingOO && gWinW>=vAnsL ){
			fnBids('leftWing').left=(-gLeftWingW - gLeftWingGap) + "px";
			fnBids('leftWing').visibility="visible";
		}else{
			fnBids('leftWing').left="0px";
			fnBids('leftWing').visibility="hidden";
		}
		
		// dRightWing
		if(gDoRightWingOO && gWinW>=vAnsR){
			fnBids('rightWing').left=(gPageHolderW + gRightWingGap) + "px";
			fnBids('rightWing').visibility="visible";
		}else{
			fnBids('rightWing').left="0px";
			fnBids('rightWing').visibility="hidden";
		}
	}
	
	/*If and only if gDoLeftWingOO is true and also the width of Body is larger than the range for the LeftWing, dLeftWing is visible. Otherwise dLeftWing is hidden, so will not show in screen.*/
/*On and Off wing end*/
//////////////////////////////////////////////////////////////////////////// 


	function getCategoryItems(categoryId)
	{
	    $('.slideshow').cycle('destroy');
	    var webMethod = '/WebPageInternalService.asmx/GetCategoryItems';
	    var parameters = "{'categoryId':'" + categoryId + "'}";
	    $.ajax({
	        type: "POST",
	        url: webMethod,
	        data: parameters,
	        contentType: "application/json; charset=utf-8",
	        dataType: "json",
	        success: function (msg) {
	            
	            $(".middleFood").html(msg.d);
	            $("#menyPopup").show();
	            bind();
	        },
	        error: function (XMLHttpRequest, textStatus, errorThrown) {
	            var err = XMLHttpRequest.responseText;
	            //throw err.Message;
	        }

	    });
	}

	function getCategorys(imageType)
	{
	    var webMethod = '/WebPageInternalService.asmx/GetCategorys';
	    var parameters = "{'imageType':'" + imageType + "'}";
	    $.ajax({
	        type: "POST",
	        url: webMethod,
	        data: parameters,
	        contentType: "application/json; charset=utf-8",
	        dataType: "json",
	        success: function (msg)
	        {
	            $(".middleFood").html(msg.d);
	            $("#categoryPopup").show();
	            bind();
	        },
	        error: function (XMLHttpRequest, textStatus, errorThrown)
	        {
	            var err = XMLHttpRequest.responseText;
	            //throw err.Message;
	        }

	    });
	}

	function getRestaurants()
	{
	    var webMethod = '/WebPageInternalService.asmx/GetRestaurants';
	    $.ajax({
	        type: "POST",
	        url: webMethod,
	        contentType: "application/json; charset=utf-8",
	        dataType: "json",
	        success: function (msg)
	        {
	            $("#citySelector").html(msg.d);
	        },
	        error: function (XMLHttpRequest, textStatus, errorThrown)
	        {
	            var err = XMLHttpRequest.responseText;
	            //throw err.Message;
	        }

	    });
	}

	function GetWeatherFromIP(ipAddress)
	{
	    $("#weatherApp .title").html("Oppdaterer...");
	    var webMethod = '/WebPageInternalService.asmx/GetWeatherFromIP';
	    var parameters = "{'ipAddress':'" + ipAddress + "'}";
	    $.ajax({
	        type: "POST",
	        url: webMethod,
	        data: parameters,
	        contentType: "application/json; charset=utf-8",
	        dataType: "json",
	        success: function (msg)
	        {
	            var q = msg.d;
	            $(".symbolImg1").attr("src", q[0]);
	            $(".symbolImg2").attr("src", q[1]);
	            $(".symbolImg3").attr("src", q[2]);
	            $(".tempLbl1").html(q[3]);
	            $(".tempLbl2").html(q[4]);
	            $(".tempLbl3").html(q[5]);
	            $("#weatherApp .title").html("Uteservering i " + q[6]);
	            $(".notInCityLink").html("&#8250; Ikke i " + q[6] + "?");
	            $(".detailLink").attr("href", q[7]);
	            $(".date1").html(q[8]);
	            $(".date2").html(q[9]);
	            $(".date3").html(q[10]);
	        },
	        error: function (XMLHttpRequest, textStatus, errorThrown)
	        {
	            var err = XMLHttpRequest.responseText;
	        }

	    });
	}

	function getWeather(zipCode)
	{
	    $("#weatherApp .title").html("Oppdaterer...");
	    var webMethod = '/WebPageInternalService.asmx/GetWeather';
	    var parameters = "{'zipCode':'" + zipCode + "'}";
	    $.ajax({
	        type: "POST",
	        url: webMethod,
	        data: parameters,
	        contentType: "application/json; charset=utf-8",
	        dataType: "json",
	        success: function (msg)
	        {
	            var q = msg.d;
	            $(".symbolImg1").attr("src", q[0]);
	            $(".symbolImg2").attr("src", q[1]);
	            $(".symbolImg3").attr("src", q[2]);
	            $(".tempLbl1").html(q[3]);
	            $(".tempLbl2").html(q[4]);
	            $(".tempLbl3").html(q[5]);
	            $("#weatherApp .title").html("Uteservering i " + q[6]);
	            $(".notInCityLink").html("&#8250; Ikke i " + q[6] + "?");
	            $(".detailLink").attr("href", q[7]);
	            $(".date1").html(q[8]);
	            $(".date2").html(q[9]);
	            $(".date3").html(q[10]);
	        },
	        error: function (XMLHttpRequest, textStatus, errorThrown)
	        {
	            var err = XMLHttpRequest.responseText;
	        }

	    });
	}

	function LoadBanners(menuPath, callback)
	{
	    var defBanner = $.Deferred();
	    var webMethod = '/WebPageInternalService.asmx/LoadBanners';
	    var parameters = "{'menuPath': '" + menuPath + "'}";
	    $.ajax({
	        type: "POST",
	        url: webMethod,
	        data: parameters,
	        contentType: "application/json; charset=utf-8",
	        dataType: "json",
	        success: function (msg)
	        {
	            callback(JSON.parse(msg.d));
	            defBanner.resolve();
	        },
	        error: function (XMLHttpRequest, textStatus, errorThrown)
	        {
	            var err = eval("(" + XMLHttpRequest.responseText + ")");
	            if (DEBUG) alert(err.Message);
	            callback(null);
	            defBanner.resolve();
	        }
	    });
	}
