﻿function SetPicture(action) {
    var id = $("#camera").attr("ref")
    $.getJSON("json/pic.ashx?action=" + action + "&id=" + id + "&type=1",
    function(data) {
        $("#camera").attr("src", data._url);
        $("#camera").attr("ref", data._id);
    });
}

function SetPictureJomba(action) {
    var id = $("#camera").attr("ref")
    $.getJSON("json/pic.ashx?action=" + action + "&id=" + id + "&type=2",
    function(data) {
        $("#camera").attr("src", data._url);
        $("#camera").attr("ref", data._id);
    });
}

function SetSeasoning(action, sid) {
    $.getJSON("json/seasoning.ashx?action=" + action + "&id=" + sid,
        function(data) {
            $("#seasoningImg").attr("src", data._picture);
            $("#seasoningTitle").text(data._title);
            $("#seasoningIntro").text(data._intro);
            $(".active").attr("class", "");
            $("#seas" + data._id).attr("class", "active");

        });
}
function SeasoningClicked() {
    $("#seasoningImg").attr("src", "images/bg-gallery.png");
}

function StartRoundPicture() {
    setInterval("SetRoundPicture() ;", 10000);
}

var roundPictureId = 0

function SetRoundPicture() {
    $.getJSON("json/roundPic.ashx?action=next&type=1&id=" + roundPictureId,
    function(data) {
        $("#roundPicture").attr("src", data._url);
        roundPictureId = data._id
    });
}
var controlValues = new Array();
function Clear(controlId) {
    if (controlValues[controlId] == document.getElementById(controlId).value || controlValues[controlId]==undefined)  {
        controlValues[controlId] = document.getElementById(controlId).value
        document.getElementById(controlId).value = ''
    }
}
function UnClear(controlId) {
    if (document.getElementById(controlId).value == '') {
        document.getElementById(controlId).value = controlValues[controlId]
    }
}
var lastItem;
function SetItem(action, location, sid, contentHolder) {
    $(contentHolder).load("json/item.ashx?action=" + action + "&location=" + location);
    $(".active").attr("class", "");
    $("#" + sid).attr("class", "active");
    window.location.href = window.location.href.split("#")[0] + "#_" + sid
    lastItem= sid
}
function SetItemJomba(action, location, sid, contentHolder) {
    $(contentHolder).load("json/ItemJomba.ashx?action=" + action + "&location=" + location);
    $(".active").attr("class", "");
    $("#" + sid).attr("class", "active");
    window.location.href = window.location.href.split("#")[0] + "#_" + sid
    lastItem= sid
}
function SetItemInit() {
    var hash = window.location.href.split("#")[1];
    var linkId = hash.substr(1);
    if ($("#" + linkId).attr("href") != undefined) {
        var href = $("#" + linkId).attr("href").replace("javascript:", "")
    } 
    eval(href);

}

function SetFirstItem(action, location, sid, contentHolder) {
    if (window.location.href.split("#").length <= 1) {
        SetItem(action, location, sid, contentHolder);
    } else {
        SetItemInit();
    }
}

var actualThemePhoto = 0;
function NextThemaPicture(imgId) {
    actualThemePhoto++;
    var photos
    if ($("#" + imgId).attr("rel") != undefined) {
        photos = $("#" + imgId).attr("rel").split(";");
        if (actualThemePhoto >= photos.length - 1) {
            actualThemePhoto = 0;
        }
        $("#" + imgId).attr("src", photos[actualThemePhoto]);
    }

}
function test() {
    $("#picturewrap").corner();
}
function GetWholeOverViewText(oid, contentHolder) {
    $(contentHolder).load("json/overview.ashx?id=" + oid);
}

/***BOOKING FORM VALIDATION***/
function ValidateRrid(controlId, validatorId) {
    var value = $("#" + controlId).get()[0].value
    if (value.length > 0 && value != controlValues[controlId]) {
        SetValid(validatorId)
    } else {
        SetInvalid(validatorId)
    }
}
function ValidateRequired(controlId, validatorId) {
    var value = $("#" + controlId).get()[0].value
    if (value.length > 0 && value!= controlValues[controlId]) {
        SetValid(validatorId)
    } else {
        SetInvalid(validatorId)
    }
}

function SetInvalid(validatorId) {
        $("#" + validatorId).attr("class", "alert invalid")
}
function SetValid(validatorId) {
        $("#" + validatorId).attr("class", "alert")
}
/***END BOOKING FORM**/


function startFototoestel() {
    loadFototoestel();
    setInterval("loadFototoestel()", 5000);
}

function loadFototoestel() {
    var r = Math.floor(Math.random() * 1000000);
    $("#fototoestel").load("Fototoestel.ashx?r=" + r);
}   