function imagePopUp(img){
    html = html = "<html><head><title>Popup</title>" + "</head><body style=\"margin: 0px 0; text-align:center;\">" + "<a href=\"javascript:window.close();\"><IMG src='" + img + "' BORDER=0 NAME=image " + "onload='window.resizeTo(document.image. width,(document.image.height*1.2))'></a>" + "</body></html>"; popup=window.open ('','image','toolbar=0,location=0, directories=0,menuBar=0, scrollbars=0,resizable=1'); popup.document.open(); popup.document.write(html);popup.document.close();
}

this.x = 200;
this.y = 200;
this.theTop = 0;
this.theLeft = 0;
function setVisible(obj) {
    obj = document.getElementById(obj);
    this.x = ((document.body.clientWidth / 2) - (obj.clientWidth / 2));
    if (obj) {
        obj.style.left = ((document.body.clientWidth / 2) - (obj.clientWidth / 2)) + 'px';
        obj.style.top = this.theTop + 'px';
    }
    obj.style.visibility = (obj.style.visibility == 'visible') ? 'hidden' : 'visible';
}
function placeIt(_obj) {
    obj = document.getElementById(_obj);
    if (obj) {
        if (document.documentElement) {
            //theLeft = document.documentElement.scrollLeft;
            this.theTop = document.documentElement.scrollTop;
        }
        else if (document.body) {
            //theLeft = document.body.scrollLeft;
            this.theTop = document.body.scrollTop;
        }

        //theLeft += x;
        //this.theTop += this.y;
        this.x = ((document.body.clientWidth / 2) - (obj.clientWidth / 2));
        //obj.style.left = theLeft + 'px';
        obj.style.left = this.x + 'px';
        obj.style.top = this.theTop + 'px';
    }
    setTimeout("placeIt('" + _obj + "')", 500);
}

function placeItScroll(evt) {
    setTimeout("placeIt('layer1')", 500)
    setTimeout("placeIt('layer2')", 500)
    setTimeout("placeIt('layer3')", 500)
    setTimeout("placeIt('layer4')", 500)
}

function placeItScrollIE() {
    setTimeout("placeIt('layer1')", 500)
    setTimeout("placeIt('layer2')", 500)
    setTimeout("placeIt('layer3')", 500)
    setTimeout("placeIt('layer4')", 500)
}

if(window.addEventListener) // Firefox 1+, Opera 9, Safari 3+, etc.
{
    window.addEventListener("scroll", placeItScroll, false);
}
else if(document.addEventListener) // Opera 7, Opera 8
{
    document.addEventListener("scroll", placeItScroll, false);
}
else if("onscroll" in self) // MSIE 6, 7 and MSIE 8
{
    self.onscroll = placeItScrollIE;
}
//window.onscroll = setTimeout("placeIt('layer1')", 500);

function showHorse(_FormInstanceUid, _IdToInsertHorse, _IdTempImageHorse)
{
    //debugger;
    
    var temp = Ext.query(_IdToInsertHorse);
    var temp2 = Ext.query(_IdTempImageHorse);
    temp[0].innerHTML = "<span class='top-paard'>" + temp2[0].innerHTML + "</span>";
    temp2[0].innerHTML = '';
    
    var taal = 'NL';
    if (document.location.href.indexOf('/en/') != -1) { taal = 'EN'; }
    else if (document.location.href.indexOf('/nl/') != -1) { taal = 'NL'; }
    
    ExtRequest('GetFormInstances', [_FormInstanceUid , taal], showHorseSucces, showHorseFailed, [_IdToInsertHorse]);
}

function showHorseSucces(result,args)
{
    var jsonData = Ext.util.JSON.decode(result.responseText);
    var tmp = this.location.pathname;
    var pos = tmp.lastIndexOf('/');
    tmp = tmp.substring(0,pos);

    var temp = Ext.query(args.callbackargs[0]);
    var name = "";
    if(Ext.util.JSON.decode(jsonData.Data[0].dataStore).Hengsten){
        name = Ext.util.JSON.decode(jsonData.Data[0].dataStore).Hengsten.Name;
    } else {
        name = Ext.util.JSON.decode(jsonData.Data[0].dataStore).Sportpaarden.Name;
    }
    var str = "<div class='arrow-left'><a class='left' href='"+tmp+"/"+jsonData.Data[0].friendlyName+".html' alt='"+name+"'></a></div>";
    
    if(Ext.util.JSON.decode(jsonData.Data[0].dataStore).Hengsten){
        name = Ext.util.JSON.decode(jsonData.Data[0].dataStore).Hengsten.Name;
    } else {
        name = Ext.util.JSON.decode(jsonData.Data[0].dataStore).Sportpaarden.Name;
    }
    str = str+"<div class='arrow-right'><a class='right' href='"+tmp+"/"+jsonData.Data[2].friendlyName+".html' alt='"+name+"'></a></div>";
    temp[0].innerHTML = str+temp[0].innerHTML;
}

function showHorseFailed(result,args) {
//debugger;
}

$(document).ready(function() {
    var logDiv = Ext.query('.logo a');

    var taal = 'nl';
    if (document.location.href.indexOf('/en/') != -1) { taal = 'en'; }
    else if (document.location.href.indexOf('/nl/') != -1) { taal = 'nl'; }

    logDiv[0].href = 'http://' + document.location.hostname + '/' + taal + '/';

/*
    var tmp = $(".detail-hengst-mov tr:last-child a")[0];
    if (tmp != null) {
        tmp.className = "alle-films";
    }
    */
    //$("a:has(img)").fancybox();
    tmp = $(".detail-hengst-mov tr a");
    if (tmp != null) {
        tmp.click(function() {
            $.fancybox({
                'padding': 0,
                'autoScale': false,
                'transitionIn': 'none',
                'transitionOut': 'none',
                'title': this.title,
                //'width': 680,
                //'height': 495,
                'href': this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
                'type': 'swf',
                'swf': {
                    'wmode': 'transparent',
                    'allowfullscreen': 'true'
                }
            });

            return false;
        });
    }
    tmp = $("a#inline");
    if (tmp != null) {
        tmp.fancybox({
            'hideOnContentClick': true
        });
    }

    tmp = $("a#stamboom-link");
    if (tmp != null) {
        tmp.fancybox();
    }

});

function detailSwitch() {
    var tmp = $(".detail-left");
    if (tmp[0].style.height == "auto") {
        tmp.css({ height: "168px" });
    } else {
        tmp.css({ height: "auto" });
    }
    var tmp = $(".detail-more-nl");
    if (tmp) {
        tmp.css({ visibility: "hidden" });
    }
    tmp = $(".detail-more-en");
    if (tmp) {
        tmp.css({ visibility: "hidden" });
    }
}

function gup( name )
{
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var tmpURL = window.location.href;
  var results = regex.exec( tmpURL );
  if( results == null )
    return "";
  else
    return results[1];
}
