;(function() {
    var $$ = jQuery.fn.flash=function(htmlOptions,pluginOptions,replace,update) {
        var block=replace||$$.replace;
        pluginOptions=$$.copy($$.pluginOptions,pluginOptions);
        if(!$$.hasFlash(pluginOptions.version)) {
            if(pluginOptions.expressInstall&&$$.hasFlash(6,0,65)) {
                var expressInstallOptions= {
                    flashvars: {
                        MMredirectURL:location,
                        MMplayerType:'PlugIn',
                        MMdoctitle:jQuery('title').text()
                    }
                };
            } else if (pluginOptions.update) {
                block=update||$$.update;
            } else {
                return this;
            }
        }
    htmlOptions=$$.copy($$.htmlOptions,expressInstallOptions,htmlOptions);
    return this.each(function() {
        block.call(this,$$.copy(htmlOptions));
    });
};
$$.copy=function() {
    var options={},flashvars={};
    for(var i=0;i<arguments.length;i++) {
        var arg=arguments[i];
        if(arg==undefined)continue;
        jQuery.extend(options,arg);
        if(arg.flashvars==undefined)continue;
        jQuery.extend(flashvars,arg.flashvars);
    }
    options.flashvars=flashvars;
    return options;
};
$$.hasFlash=function() {
    if(/hasFlash\=true/.test(location))return true;
    if(/hasFlash\=false/.test(location))return false;
    var pv=$$.hasFlash.playerVersion().match(/\d+/g);
    var rv=String([arguments[0],arguments[1],arguments[2]]).match(/\d+/g)||String($$.pluginOptions.version).match(/\d+/g);
    for(var i=0;i<3;i++) {
        pv[i]=parseInt(pv[i]||0);
        rv[i]=parseInt(rv[i]||0);
        if(pv[i]<rv[i])return false;
        if(pv[i]>rv[i])return true;
    }
    return true;
};
$$.hasFlash.playerVersion=function() {
    try{
        try {
            var axo=new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6');
            try {
                axo.AllowScriptAccess='always';
            } catch(e) { return'6,0,0'; }
        } catch(e){}
        return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g,',').match(/^,?(.+),?$/)[1];
    } catch(e) {
        try {
            if(navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){return(navigator.plugins["Shockwave Flash 2.0"]||navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g,",").match(/^,?(.+),?$/)[1];}
        } catch(e){}
    }
    return'0,0,0';
};
$$.htmlOptions= {
    height:'100%',
    flashvars:{},
    pluginspage:'http://www.adobe.com/go/getflashplayer',
    src:'#',
    type:'application/x-shockwave-flash',
    width:'100%'
};
$$.pluginOptions= {
    expressInstall:false,
    update:true,
    version:'6.0.65'
};
$$.replace=function(htmlOptions) {
	this.innerHTML = $$.transform(htmlOptions)+'<div class="alt">'+this.innerHTML+'</div>';
	jQuery(this)
		.addClass('flash-replaced')
};
$$.update=function(htmlOptions) {
    var url=String(location).split('?');
    url.splice(1,0,'?hasFlash=true&');
    url=url.join('');
    var msg='<p>This content requires the Flash Player. <a href="http://www.adobe.com/go/getflashplayer">Download Flash Player</a>. Already have Flash Player? <a href="'+url+'">Click here.</a></p>';
    this.innerHTML='<span class="alt">'+this.innerHTML+'</span>';
    jQuery(this)
        .addClass('flash-update')
        .prepend(msg);
};
function toAttributeString() {
    var s='';
    for(var key in this)
        if(typeof this[key]!='function')
            s+=key+'="'+this[key]+'" ';
    return s;
};
function toFlashvarsString() {
    var s='';
    for(var key in this)
        if(typeof this[key]!='function')
            s+=key+'='+encodeURI(this[key])+'&';
        return s.replace(/&$/,'');
};
$$.transform=function(htmlOptions) {
    htmlOptions.toString=toAttributeString;
    if(htmlOptions.flashvars)htmlOptions.flashvars.toString=toFlashvarsString;
    return'<embed '+String(htmlOptions)+'/>';
};
if(window.attachEvent) {
    window.attachEvent("onbeforeunload",function() {
        __flash_unloadHandler=function(){};
        __flash_savedUnloadHandler=function(){};
    });
}
})();

/* function setFlashHeight(newHeight){
    $('#collage-image').animate({height: newHeight}, 1000);
} */

function setFlashHeight(newH){
	divid = 'collage-image';
	document.getElementById(divid).style.height = newH+"px";
}
function canResizeFlash(){
	var ua = navigator.userAgent.toLowerCase();
	var opera = ua.indexOf("opera");
	if( document.getElementById ){
		if(opera == -1) return true;
		else if(parseInt(ua.substr(opera+6, 1)) >= 7) return true;
	}
	return false;
}

$(function(){
    if(document.URL.match('boligbyggelag','i') ) {
        $('#collage').flash({
        	wmode: 'transparent',
			bgcolor: '#000000',
		    src: '/templates/Teleroer/flash/sparx.swf',
    		width: 968,
	    	height: 261,
			flashvars: {
				xmlURL: '/templates/Teleroer/flash/boligbyggelag.xml',
				fileURL: '/templates/Teleroer/flash/bilder/',
				siteURL: '/',
				interval: '10000',
				visCaption: '1',
                CaptionX: '0',
				CaptionY: '205',
				CaptionBackW: '1000',
				CaptionBackH: '200',
				MessageX: '20',
				MessageY: '18',
				MessageC: '0xffffff',
				visAntallBilder: '1',
				VelgBildeX: '960',
				VelgBildeY: '18',
				VelgBildeW: '15',
				VelgBildeH: '15',
				VelgBildeD: '25'
			}
    	},
	    {
	        version: 8
    	});
    } else if (document.URL.match('offentlig','i') ) {
        $('#collage').flash({
        	wmode: 'transparent',
			bgcolor: '#000000',
		    src: '/templates/Teleroer/flash/sparx.swf',
    		width: 968,
	    	height: 261,
			flashvars: {
				xmlURL: '/templates/Teleroer/flash/offentlig.xml',
				fileURL: '/templates/Teleroer/flash/bilder/',
				siteURL: '/',
				interval: '10000',
				visCaption: '1',
                CaptionX: '0',
				CaptionY: '205',
				CaptionBackW: '1000',
				CaptionBackH: '200',
				MessageX: '20',
				MessageY: '18',
				MessageC: '0xffffff',
				visAntallBilder: '1',
				VelgBildeX: '960',
				VelgBildeY: '18',
				VelgBildeW: '15',
				VelgBildeH: '15',
				VelgBildeD: '25'
			}
    	},
	    {
	        version: 8
    	});
    } else if (document.URL.match('naering','i') ) {
        $('#collage').flash({
        	wmode: 'transparent',
			bgcolor: '#000000',
		    src: '/templates/Teleroer/flash/sparx.swf',
    		width: 968,
	    	height: 261,
			flashvars: {
				xmlURL: '/templates/Teleroer/flash/naering.xml',
				fileURL: '/templates/Teleroer/flash/bilder/',
				siteURL: '/',
				interval: '10000',
				visCaption: '1',
                CaptionX: '0',
				CaptionY: '205',
				CaptionBackW: '1000',
				CaptionBackH: '200',
				MessageX: '20',
				MessageY: '18',
				MessageC: '0xffffff',
				visAntallBilder: '1',
				VelgBildeX: '960',
				VelgBildeY: '18',
				VelgBildeW: '15',
				VelgBildeH: '15',
				VelgBildeD: '25'
			}
    	},
	    {
	        version: 8
    	});
    } else if (document.URL.match('industri','i') ) {
        $('#collage').flash({
        	wmode: 'transparent',
			bgcolor: '#000000',
		    src: '/templates/Teleroer/flash/sparx.swf',
    		width: 968,
	    	height: 261,
			flashvars: {
				xmlURL: '/templates/Teleroer/flash/industri.xml',
				fileURL: '/templates/Teleroer/flash/bilder/',
				siteURL: '/',
				interval: '10000',
				visCaption: '1',
                CaptionX: '0',
				CaptionY: '205',
				CaptionBackW: '1000',
				CaptionBackH: '200',
				MessageX: '20',
				MessageY: '18',
				MessageC: '0xffffff',
				visAntallBilder: '1',
				VelgBildeX: '960',
				VelgBildeY: '18',
				VelgBildeW: '15',
				VelgBildeH: '15',
				VelgBildeD: '25'
			}
    	},
	    {
	        version: 8
    	});
    } else if (document.URL.match('privat','i') ) {
        $('#collage').flash({
        	wmode: 'transparent',
			bgcolor: '#000000',
		    src: '/templates/Teleroer/flash/sparx.swf',
    		width: 968,
	    	height: 261,
			flashvars: {
				xmlURL: '/templates/Teleroer/flash/privat.xml',
				fileURL: '/templates/Teleroer/flash/bilder/',
				siteURL: '/',
				interval: '10000',
				visCaption: '1',
                CaptionX: '0',
				CaptionY: '205',
				CaptionBackW: '1000',
				CaptionBackH: '200',
				MessageX: '20',
				MessageY: '18',
				MessageC: '0xffffff',
				visAntallBilder: '1',
				VelgBildeX: '960',
				VelgBildeY: '18',
				VelgBildeW: '15',
				VelgBildeH: '15',
				VelgBildeD: '25'
			}
    	},
	    {
	        version: 8
    	});
    } else if (document.URL.match('om-teleroer','i') ) {
        $('#collage').flash({
        	wmode: 'transparent',
			bgcolor: '#000000',
		    src: '/templates/Teleroer/flash/sparx.swf',
    		width: 968,
	    	height: 261,
			flashvars: {
				xmlURL: '/templates/Teleroer/flash/omoss.xml',
				fileURL: '/templates/Teleroer/flash/bilder/',
				siteURL: '/',
				interval: '10000',
				visCaption: '1',
                CaptionX: '0',
				CaptionY: '205',
				CaptionBackW: '1000',
				CaptionBackH: '200',
				MessageX: '20',
				MessageY: '18',
				MessageC: '0xffffff',
				visAntallBilder: '1',
				VelgBildeX: '960',
				VelgBildeY: '18',
				VelgBildeW: '15',
				VelgBildeH: '15',
				VelgBildeD: '25'
			}
    	},
	    {
	        version: 8
    	});
    } else {
        $('#collage').flash({
        	wmode: 'transparent',
			bgcolor: '#000000',
		    src: '/templates/Teleroer/flash/sparx.swf',
    		width: 968,
	    	height: 261,
			flashvars: {
				xmlURL: '/templates/Teleroer/flash/startsiden.xml',
				fileURL: '/templates/Teleroer/flash/bilder/',
				siteURL: '/',
				interval: '10000',
				visCaption: '1',
                CaptionX: '0',
				CaptionY: '205',
				CaptionBackW: '1000',
				CaptionBackH: '200',
				MessageX: '20',
				MessageY: '18',
				MessageC: '0xffffff',
				visAntallBilder: '1',
				VelgBildeX: '960',
				VelgBildeY: '18',
				VelgBildeW: '15',
				VelgBildeH: '15',
				VelgBildeD: '25'
			}
    	},
	    {
	        version: 8
    	});
	}
});
