function setPhotoPath(element,newSrc) {
    //$(element).fadeOut("fast");
    $(element).attr({ src: "http://price-list.sopserver.com/img/loading_aqua.gif", alt: "image" }); 
    $(element).attr({ src: newSrc, alt: "image" });
}
function redrawGallery(getPath) {
      $("#galleryTop").animate({opacity: 0.4}, 1000, function() {
          $.get(getPath, function(data) {
          //alert("Data Loaded: " + data); 
              $("#galleryTop").html(data);  
              $("#galleryTop").animate({opacity: 1}, 1000 );      
          });
      });
}

function redrawConstructionGallery(getPath) {
      $("#constructionPhoto").animate({opacity: 0.4}, 1000, function() {
          $.get(getPath, function(data) {
          //alert("Data Loaded: " + data); 
              $("#constructionPhoto").html(data);  
              $("#constructionPhoto").animate({opacity: 1}, 1000 );      
          });
      });
}

function slideWindow(ref) {
     state = $("#" + ref).css('display');
     if(state=='none') {
        $("#" + ref).slideDown("slow");       
     } else {
        $("#" + ref).slideUp("slow"); 
     }
}

function showBigFoto(path,adm,hash) {
var onScroll = getScrollPos();
var partOfPath = path.split("=");
var odskok = 10;
var getPath = "pagedso-picturemod-hash@" + partOfPath[1] + ".html";
var getInfoPath = "pagedso-pinfo-hash@" + partOfPath[1] + ".html";

    $("#imgPrew").css("margin-top",onScroll);
    $("#imgPrew").fadeIn("fast");
    if(adm == 1) {
        $.get(getPath, function(data) {
            $("#imgPrew").html('<img src="' + path + '" onClick="unloadPhoto();" id="dynBigW"><div id="imgPrew2"></div>');
            $("#imgPrew2").html('<input type="button" value="(erase)" onClick="ask(\'/update:Project:erasePhoto/hash:' + hash + '\');" style="color: red;">' + data);    
        });            
    } else {
        $.get(getInfoPath, function(data2) {
            if(data2 != '') {
                var iAppend = '<div class="imgdesc">' + data2 + '</div>';
            }                                     
            $("#imgPrew").html('<img src="' + path + '" onClick="unloadPhoto();">' + iAppend);
        });  
    }  
}



function imageLoadEvent( e ) {
    alert("aaa");
}

function setAfterLoad() {
    window.alert("helo");
        //$("#imgPrew2").html('<input type="button" value="(erase)" onClick="ask(\'/update:Project:erasePhoto/hash:' + hash + '\');" style="color: red;">' + data);    
}

function unloadPhoto() {
   $("#imgPrew").fadeOut("fast");
   $("#imgPrew").html('Image not loaded....'); 
}

function unloadPhoto3() {
   $("#imgPrew3").fadeOut("fast");
   $("#imgPrew3").html('Image not loaded....'); 
}

function kontrola(formular) {
    if(formular.password.value == formular.pass_check.value) {
        //window.alert('Registrace proběhla úspěšně');
        val = true;
    } else {
        window.alert('password mismatch');
        val = false;
    }
    
return val;
}

function addToMC(id,state) {
    if(state == 1) {
        $.get("/update:Mycrestyl:addToMC/id:" + id, function(data) {
            alert("Přidáno do mého crestylu");      
        });
    } else {
        alert("Prosíme, přihlašte se");    
    }   
}

function faqExpand(id) {
    
}

function releaseWindow(id) {
   $("#" + id).fadeIn("fast");
}
function closeWindow(id) {
   $("#" + id).fadeOut("fast");
}
function loadComment(id) {
    $.get("pagedso-loadNote-id;" + id + ".html", function(data) {
       document.getElementById('fmid_10').value = id; 
       document.getElementById('fmid_9').value = data; 
       $("#notepad").fadeIn("fast");
       updateOpened();          
    }); 
}

function updateOpened() {
 $(".selectors").val("");
opened = $(".myButtText:visible");
    for (i=0;i<=opened.length;i++)
    {
        thisVal = $(".selectors").val();
        $(".selectors").val(thisVal + opened[i].id + ",");   
    }               
}

function rollBack() {
    actualId = document.getElementById('fotoId').value;
    newId =  (parseInt(actualId) - 1);
    if(newId >= 0) {
        $("#bigFoto").attr({ src: "dataSourceParent.php?hash=" + unFoto[newId], alt: "image" });
        document.getElementById('fotoId').value = newId;
        $("#rollForwardButton").fadeIn("fast");          
    }
    if(newId == 0) {
        $("#rollBackButton").fadeOut("fast");
    }
}

function rollForward() {
    actualId = document.getElementById('fotoId').value;
    newId =  (parseInt(actualId) + 1);
    if(newId <= 3) {
        $("#bigFoto").attr({ src: "dataSourceParent.php?hash=" + unFoto[newId], alt: "image" });
        document.getElementById('fotoId').value = newId;
        $("#rollBackButton").fadeIn("fast");          
    }
    if(newId == 3) {
        $("#rollForwardButton").fadeOut("fast");
    }    
}

function getScrollPos() {
var ScrollTop = document.body.scrollTop;
if (ScrollTop == 0)
{
    if (window.pageYOffset)
        ScrollTop = window.pageYOffset;
    else
        ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
}
    return ScrollTop;
    //window.alert("x:" + ScrollTop + "y:" + ScrollTop);
}

function checkSamePw(ref,ref2) {
    p1 =  $("#" + ref2).val();
    p2 = ref.value;    
    
    if(p1==p2) {
        isOk = true;    
        ref.style.background = "#80FF80";
    } else {
        isOk = false;    
        ref.style.background = "#FF8080";    
    }
}

function kontrola2() {
    if(isOk) {
        val = true;
    } else {
        window.alert('password mismatch');
        val = false;
    }

return val;
}

function ask(red) {
    ret = window.confirm("Perform action:\n\n" + red);
    if(ret) {
        parent.location = red;
    }
}

/**/

function showBigFoto2(path,adm,hash) {

var onScroll = getScrollPos();
var odskok = 17;
var sW = screen.width;
var sH = screen.height;
var swH = document.documentElement.clientHeight;
var partOfPath = path.split("=");
var oid = 0;

for (i=0;i<=unFotoGlob.length;i++) {
    if(unFotoGlob[i]==partOfPath[1]) {
        oid = i;
    }
}  

var backer = unFotoGlob[(oid-1)];
var nexter = unFotoGlob[(oid+1)];
var backButt_a = '<a id="fButtLeft" onClick="showBigFoto2(\'dataSourceParent.php?hash=' + backer + '\');"><</a>';
var backButt_p = '<a id="fButtLeft_p" class="fButt_pasive"><</a>';
var nextButt_a = '<a id="fButtRight" onClick="showBigFoto2(\'dataSourceParent.php?hash=' + nexter + '\');">></a>';
var nextButt_p = '<a id="fButtRight_p" class="fButt_pasive">></a>';
var xButt = '<a id="xButt" onClick="unloadPhoto3();">x</a>';

if(unFotoGlob[0]==partOfPath[1]) {
    var bb = backButt_p;
} else {
    var bb = backButt_a;
}

var ident = (unFotoGlob.length-1);

if(unFotoGlob[ident]==partOfPath[1]) {
    var nb = nextButt_p;
} else {
    var nb = nextButt_a;
}

var pop = "";
var getInfoPath = "pagedso-pinfo-hash@" + partOfPath[1] + ".html";
    
    
    
$.get(getInfoPath, function(data2) {
   pop = '<div class="imgfoot" id="imgfoot">'+data2+'</div>';
   $("#imgPrew3").css("margin-top",(onScroll-odskok));
   $("#imgPrew3").fadeIn("fast");
   $("#imgPrew3").html('<table border="0" align="center"><tr><td><img src="' + path + '" id="aPimage" onClick="unloadPhoto3();"><br />' + bb + xButt + nb + "</td></tr><tr><td>" + pop + "</tr></td></table>");
   if(data2 != '') {
    $("#imgfoot").fadeIn("fast");
   }
});         

//document.getElementById('aPimage').height = (swH-odskok-1);           
//document.getElementById('aPimage').height = 400;
}

function showBigFoto3(path,adm,hash) {
var onScroll = getScrollPos();
var odskok = 17;
var sW = screen.width;
var sH = screen.height;
var swH = document.documentElement.clientHeight;
var partOfPath = path.split("=");
var oid = 0;

for (i=0;i<=constructionPhoto.length;i++) {
    if(constructionPhoto[i]==partOfPath[1]) {
        oid = i;
    }
}  

var backer = constructionPhoto[(oid-1)];
var nexter = constructionPhoto[(oid+1)];
var backButt_a = '<a id="fButtLeft" onClick="showBigFoto3(\'dataSourceParent.php?hash=' + backer + '\');"><</a>';
var backButt_p = '<a id="fButtLeft_p" class="fButt_pasive"><</a>';
var nextButt_a = '<a id="fButtRight" onClick="showBigFoto3(\'dataSourceParent.php?hash=' + nexter + '\');">></a>';
var nextButt_p = '<a id="fButtRight_p" class="fButt_pasive">></a>';
var xButt = '<a id="xButt" onClick="unloadPhoto3();">x</a>';

if(constructionPhoto[0]==partOfPath[1]) {
    var bb = backButt_p;
} else {
    var bb = backButt_a;
}

var ident = (constructionPhoto.length-1);

if(constructionPhoto[ident]==partOfPath[1]) {
    var nb = nextButt_p;
} else {
    var nb = nextButt_a;
}

var pop = "";
var getInfoPath = "pagedso-pinfo-hash@" + partOfPath[1] + ".html";
    
    
    
$.get(getInfoPath, function(data2) {
   pop = '<div class="imgfoot" id="imgfoot">'+data2+'</div>';
   $("#imgPrew3").css("margin-top",(onScroll-odskok));
   $("#imgPrew3").fadeIn("fast");
   $("#imgPrew3").html('<table border="0" align="center"><tr><td><img src="' + path + '" id="aPimage" onClick="unloadPhoto3();"><br />' + bb + xButt + nb + "</td></tr><tr><td>" + pop + "</tr></td></table>");
   if(data2 != '') {
    $("#imgfoot").fadeIn("fast");
   }
});         

//document.getElementById('aPimage').height = (swH-odskok-1);           
//document.getElementById('aPimage').height = 400;
}


function getScrollPos() {
var ScrollTop = document.body.scrollTop;
if (ScrollTop == 0)
{
    if (window.pageYOffset)
        ScrollTop = window.pageYOffset;
    else
        ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
}
    return ScrollTop;
    //window.alert("x:" + ScrollTop + "y:" + ScrollTop);
}

function showGoogleMap(x,y,name) {
    myRef = window.open('mapa.html',name,'left=0,top=0,width=900,height=700,toolbar=0,resizable=0');
    myRef.xko = x;
    myRef.yko = y;
}

function fadeEdit(path) {
var onScroll = getScrollPos();
var odskok = 17;
    $.get(path, function(data) {
        $("#imgPrew").css("margin-top",(onScroll-odskok));    
        $("#imgPrew").css("padding-top",'70px');    
        $("#imgPrew").html('<div id="wsPageEdit">' + data + '</div>');
        $("#imgPrew").fadeIn("fast");                                            
    });  

}



