/*
Includes javascript-functions for general use
*/

/*
Function for adding to favorites
*/
function bookmark(sUrl, sName)
{
    if (document.all)
        { // For Internet Explorer:
            window.external.AddFavorite(sUrl, sName);
        }
    else if (window.sidebar) 
        { // For Firefox:
             window.sidebar.addPanel(sName, sUrl,'');
        }
}
/*
Function for adding to facebook
*/
function fbs_click() 
{
    u=document.location;
    t=document.title;
    window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'Aftenposten','toolbar=0,status=0,width=626,height=436');
    return false;
}


/*
Trims whitespace from strings
 */
function trim(s)
{
    var l=0; var r=s.length -1;
    while(l < s.length && s[l] == ' ')
    {	l++; }
    while(r > l && s[r] == ' ')
    {	r-=1;	}
    return s.substring(l, r+1);
}


/* Function for displaying flash objects */
function showFlashObject(url, width, height)
{
    var flashTag = '<object id="movieplayer" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'
    + 'width="' + width + '" height="' + height + '"'
    + 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">'
    + '<param name="movie" value="' +url +'" /><param name="quality" value="high" />'
    + '<param name="wmode" value="transparent" />'
    + '<embed src="' + url +'" quality="high" wmode="opaque" '
    + 'width="' + width + '" height="' + height + '"'
    + 'quality="high"'
    + 'type="application/x-shockwave-flash"'
    + 'pluginspage="http://www.macromedia.com/go/getflashplayer">'
    + '<\/embed>'
    + '<\/object>';
    document.write(flashTag);
}
/*Syntax for flashObject.write()

    Kun URL er p�krevd
    flashObject.write("test.swf", {
        width:"100px",
        height:"100px",
        version:"7.0.0",
        params: {
            wmode:"opaque",
            bgcolor:"#fff"
            },
        attributes: {
            key:"value",
            key:"value"
            },
        flashvars: {
            key:"value"
            },
        id:"minid"
    });

 */
function flashObject(){
    this.id = 1;
    this.options = {
        width:"100%",
        height:"100%",
        version:"8.0.0",
        params: {},
        flashvars: {},
        attributes:{},
        alt:""
    };

    this.write= function (url, options) {
        var instanceOptions = this.options;
        instanceOptions.id = 'flashEl'+this.id;
        if (typeof(options) != 'undefined') {
            for (var key in options) {
                instanceOptions[key] = options[key];
            }
        }
        document.write("<div id='"+instanceOptions['id']+"'>"+instanceOptions['alt']+"</div>");
        swfobject.embedSWF(url, instanceOptions['id'], instanceOptions['width'], instanceOptions['height'], instanceOptions['version'], "", instanceOptions['flashvars'], instanceOptions['params'], instanceOptions['attributes']);
        this.id++;
    }
}
flashObject = new flashObject();

/* Kommer til aa forsvinne er erstattet med showFlashObject() funksjonen */
function visFlash(url, width, height)
{
    var flashTag = '<object id="movieplayer" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'
    + 'width="' + width + '" height="' + height + '"'
    + 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">'
    + '<param name="movie" value="' +url +'" /><param name="quality" value="high" />'
    + '<param name="wmode" value="transparent" />'
    + '<embed src="' + url +'" quality="high" wmode="opaque" '
    + 'width="' + width + '" height="' + height + '"'
    + 'quality="high"'
    + 'type="application/x-shockwave-flash"'
    + 'pluginspage="http://www.macromedia.com/go/getflashplayer">'
    + '<\/embed>'
    + '<\/object>';
    document.write(flashTag);
}


(function($) {
    $('.onClickEventHandler').live('click', function(e) {
        var href = $(this).attr('data-href');

        if(e.ctrlKey) {
            window.open(href);
        }
        else {
            window.location.href = href;
        }
        e.preventDefault();
    });
})(jQuery);
