function makeClassHandler( obj )
{

    if ( obj.className.length > 0 ) {
	obj.classes = obj.className.split( ' ' );
    }
    else {
	obj.classes = new Array();
    }

    obj.addClass = function( c ) {
	for ( var i = 0 ; i < this.classes.length; i++ ) {
	    if ( this.classes[i] == c ) {
		return true;
	    }
	}
	this.classes.push( c );
	this.updateClassName();
	return true;
    }

    obj.dropClass = function( c ) {
	for ( var i = 0 ; i < this.classes.length; i++ ) {
	    if ( this.classes[i] == c ) {
                this.classes[i] = '';
		//		this.classes.splice( i, 1 );
		this.updateClassName();
		return true;
	    }
	}
	return false;
    }

    obj.hasClass = function( c ) {
	for ( var i = 0 ; i < this.classes.length; i++ ) {
	    if ( this.classes[i] == c ) {
		return true;
	    }
	}
	return false;
    }
    
    obj.updateClassName = function(){
	this.className = this.classes.join( ' ' );
    }

}

function getById( id ) {
    var ret = new Object();

    if ( document.getElementById ) {
	ret.obj   = document.getElementById(id);
	if ( ret.obj && ret.obj.style ) {
	    ret.style = document.getElementById(id).style;
	}
    }
    else if ( document.all ) {
	ret.obj   = document.all[id];
	ret.style = document.all[id].style;
    }
    else if ( document.layers ) {
	ret.obj   = document.layers[id];
	ret.style = document.layers[id];
    }

    if ( ret.obj ) {
	return ret;
    }
    else {
	return false;
    }
}

function getPopupOnClick( windowName )
{
    return function() {

	var width = this.imageWidth;
	var height = this.imageHeight;
	
	var needsScrollbar = false;
	
	if ( width > screen.availWidth ) {
	    width = screen.availWidth;
	    needsScrollbar = true;
	}
	
	if ( height > screen.availHeight ) {
	    height = screen.availHeight;
	    needsScrollbar = true;
	}
	
	if ( needsScrollbar ) { 
	    height += 21;
	}
	
	var newWindow = window.open( this.href, windowName, "width=" + width + ",height=" + height + ",directories=no,fullscreen=no,location=no,menubar=no,resizable=yes,scrollbars=" + ( needsScrollbar ? "yes" : "no" ) + ",status=no,toolbar=no" );
	if ( window.focus ) {
	    newWindow.focus();
	}
	
	return false;
    }

}

init = function()
{

//    alert( screen.width + " " + screen.height );
//    alert( screen.availWidth + " " + screen.availHeight );

    // different link behaviours
    var links = document.getElementsByTagName('a');
    for ( i = 0; i < links.length; i++ ) {
	var l = links[i];
	makeClassHandler( l );

	if ( l.hasClass( 'coverPopup1' ) ) {
	    l.imageWidth = 1417;
	    l.imageHeight = 667;

	    l.onclick = getPopupOnClick( 'coverPopup1' );
	}

	if ( l.hasClass( 'coverPopup2' ) ) {
	    l.imageWidth = 1417;
	    l.imageHeight = 691;

	    l.onclick = getPopupOnClick( 'coverPopup2' );
	}

	if ( l.hasClass( 'coverPopup3' ) ) {
	    l.imageWidth = 1420;
	    l.imageHeight = 690;

	    l.onclick = getPopupOnClick( 'coverPopup3' );
	}

	if ( l.hasClass( 'coverPopup4' ) ) {
	    l.imageWidth = 2046;
	    l.imageHeight = 978;

	    l.onclick = getPopupOnClick( 'coverPopup4' );
	}

	if ( l.hasClass( 'coverPopup5' ) ) {
	    l.imageWidth = 2835;
	    l.imageHeight = 1406;

	    l.onclick = getPopupOnClick( 'coverPopup5' );
	}
/*
	// external links
        if( l.hasClass( 'external' ) ) {
            l.onclick=function() {
		//var newName = this.href.substring( 0, this.href.length-4 );
		//alert( newName );
                var newWindow = window.open( this.href, 'new' );
                if ( window.focus ) {
                    newWindow.focus();
                }

                return false;
            }
        }
*/
    }
    

/*
    // flash popup
    var popupLink1 = getById( 'coverPopup1' );
    if ( popupLink1 ) {
	popupLink1.obj.onclick = function() {
	    trace( "!!" );
	    var newWindow = window.open( this.href, 'popupFlash1', "width=800,height=600,directories=no,fullscreen=no,location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no" );
	    if ( window.focus ) {
		newWindow.focus();
	    }

	    return false;
	}
    }
	
	// flash popup2
    var popupLink2 = getById( 'coverPopup2' );
    if ( popupLink2 ) {
	popupLink2.obj.onclick = function() {
	    var newWindow = window.open( this.href, 'popupFlash2', "width=800,height=600,directories=no,fullscreen=no,location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no" );
	    if ( window.focus ) {
		newWindow.focus();
	    }

	    return false;
	}
    }
*/

}

window.onload = init;

