
function externalLinks() {
    if (!document.getElementsByTagName) return;
    var anchors = document.getElementsByTagName("a");
    for (var i=0; i<anchors.length; i++) {
        var anchor = anchors[i];
        if (anchor.getAttribute("href") &&
            anchor.getAttribute("rel") == "external")
            anchor.target = "_blank";
    }
}
$(document).ready(externalLinks);

// search google form
function submitGoogleForm(googleform) {
    if (googleform.q.value.search(/\S.+/)) return false;
    switch(googleform.meta1[((ssoform.meta1[0].checked == true) ? 0 : 1)].value) {
		// no value, no action
		case "":
	
		// search vol.at only	
		case "vol.at":
			google_form.action = "http://www.vol.at/search.aspx";
			google_form.method = "get";
			break;
	  
		// google
		default:
			googleform.action = "http://www.vol.at/search.aspx";
			googleform.method = "get";
			break;
	}
	return true;
}


// function for onfocus background change
function changeInputFocus(input,color){
	input.style.backgroundColor=color; input.style.color='#000';
}

function changeInputBlur(input,color){
	input.style.backgroundColor=color; input.style.color='#000';
}

function displayWindow(theURL,winName,features,myWidth,myHeight,isCenter) {
    
    if(window.screen)if(isCenter)if(isCenter=="true"){
        var myLeft = (screen.width-myWidth)/2;
        var myTop = (screen.height-myHeight)/2;
        features+=((features!='')?',':'');
        features+='left='+myLeft+',top='+myTop;
    }
    
    var params = features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight+',scrollbars,resizable';
    winName="fullimage"; // remember that you get a error on IE if your winName has special charas like "." etc.
    var win = window.open(theURL, winName, params);
    
    win.focus();

}




// ajax hack to create correct camefrom url for the register and login urls
// search and replace. e.g. for all  ajaxaddtofavorites to viewer.html
// inside the favorite-added ajax view
function searchAndReplaceLinkPattern(dom_id, search, replace){
    elements = $(dom_id).getElementsByTagName("a");
    for (var i=0; i<elements.length; i++){
        if (!elements[i].getAttribute("href")) continue;
        var href = elements[i].getAttribute("href");
        href = href.split(search).join(replace);
        elements[i].setAttribute("href", href);
    }
}

/**
    opens the link list. 
    gets called when the user klicks on the link inside
    vol_global_sections.pt
    
    the function displays the linklist and hides it again
    after rollout.....
    
    @requires   prototype library.
*/
function openFeedbackLinkList(){
    $("#feedbacklinklist").toggle();
}

/**
   Ajax Navigation Box (image slider in IRight)

   searches for the following nodes and attaches the ajax events onto them:
   ajaxnavarrowleft_{prefix}
   ajaxnavarrowright_{prefix}
   ajaxnavtarget_{prefix}

   http://localhost:8080/++skin++VIENNA/teleport.mediaportal/members.jukart/Australia4-3.JPG/viewer.html?unavstart=43
*/
navigations = new Array();

AjaxNavigation = function(prefix, amount, start){
    this.prefix = prefix;
    this.amount = amount; // total amount of items. 
    this.currentpos = start; 
    
    // attach Event on the left and the right link
    var leftlink = this.getLink("ajaxnavarrowleft_"+this.prefix);

    if (leftlink){
        leftlink.setAttribute("href", "javascript:ajaxNavMove('"+this.prefix+"', 'l')");
    }

    var rightlink = this.getLink("ajaxnavarrowright_"+this.prefix);
    if (rightlink){
        rightlink.setAttribute("href", "javascript:ajaxNavMove('"+this.prefix+"', 'r')");
    }
    
    
    this.checkArrowVisibility();
}

AjaxNavigation.prototype.getLink = function(searchNode){
    return $("a", $("#"+searchNode))[0]; //.getElementsByTagName("a")[0];
}

AjaxNavigation.prototype.moveLeft = function(){
    this.currentpos -= 3;
    if (this.currentpos < 0) this.currentpos = 0;
    this.update();
}

AjaxNavigation.prototype.moveRight = function(){
    this.currentpos += 3;
    this.update();
}

AjaxNavigation.prototype.update = function(){
    params = new Object();
    params[this.prefix+"start"] = this.currentpos;
        
    $("#ajaxnavtarget_"+this.prefix).load(
        "ajaxnavigation-"+this.prefix,
        params,
        function(){}
        );
        
    this.checkArrowVisibility();
}

AjaxNavigation.prototype.checkArrowVisibility = function(){
    
    var leftlink = $(this.getLink("ajaxnavarrowleft_"+this.prefix));
    var rightlink = $(this.getLink("ajaxnavarrowright_"+this.prefix));
        
    if (leftlink){
        if (this.currentpos>0){
            leftlink.css("visibility", "visible");           
        }
        else{
            leftlink.css("visibility", "hidden");
        }
    }
    
    if (rightlink){
        //alert("current: "+this.currentpos+" amount: "+this.amount);
        if(this.currentpos > this.amount - 4){
            rightlink.css("visibility", "hidden");
        }
        else{
            rightlink.css("visibility", "visible");
        }
    }
}

function ajaxNavMove(prefix, direction){
    for (var i=0; i<navigations.length; i++){
        if(navigations[i].prefix == prefix){
            if (direction == "r"){
                navigations[i].moveRight();
            }
            else{
                navigations[i].moveLeft();
            }
        }
    }
}

function initializeAjaxNavigation(prefix, fullamount, start){
    nav = new AjaxNavigation(prefix, fullamount, start);
    navigations.push(nav);
}