function implementShadowbox( mc , dealerid ){

	var isMobile, useragent, hostname;
    
	if ( implementShadowbox.ran ) {
	
	    // run only once!
		return;
	
	}
	
	if ( !Shadowbox ) {
	
	    throw "Error! Missing Shadowbox script!";
	
	}
	
	isMobile = false;
	useragent = navigator.userAgent.toLowerCase();

	
	if (screen.width < 1000 ||
                useragent.indexOf('iphone') != -1 ||
                useragent.indexOf('ipad') != -1 ||
                useragent.indexOf('ipod') != -1 ||
                useragent.indexOf('android') != -1 ||
                useragent.indexOf('blackberry') != -1 ||
                useragent.indexOf('webos') != -1 ||
                useragent.indexOf('symbian') != -1) {
        isMobile = true;
    } 
	
	// sync domain names for cross browser communication
	hostname = location.hostname.split('.')[location.hostname.split('.').length - 2];
    hostname += '.';
    hostname += location.hostname.split('.')[location.hostname.split('.').length - 1];
    document.domain = hostname;
	
	// add rel=shadowbox to each relevant link.
    $$( "a" ).each( function ( el ) {
		
		var params,url;
		
	    if ( !/(?:^|\s)no-shadowbox(?:\s|$)/.test( el.className) && /^http:\/\/(?:imsbro|imsnwsbrf)/i.test( el.href )) {
	   
			el.rel = "shadowbox";
			
			url = el.href.split( "?" )[ 0 ];
			params = el.href.split( "?" )[ 1 ] || "";
			params = params.toQueryParams();
			
			if ( mc && !params.mc ) {
			
			    params.mc = mc;
			
			}

			if ( dealerid && dealerid !== "0" ) {
			
				params.vestigingid = dealerid;
				
			}
			
			el.href = url + "?" + Object.toQueryString( params );
			
			if ( isMobile ) {
				el.rel = "";
				el.target = "_blank";
			}
			
			el = null;
 
		}
	   
	} );
	
	implementShadowbox.ran = true;
	
	if ( !isMobile ) {
		// Initialize Shadowbox.
		Shadowbox.init( {
		
			displayNav: false,
			animate: false,
		    
			onOpen: function () {
			
			    $( "sb-container" ).addClassName( "volkswagen" );
				$$( ".youtube-iframe" ).invoke( "setStyle", {visibility: "hidden"} );
			
			},
			
			onClose: function () {
			
			    $( "sb-wrapper-inner" ).hide();
				$$( ".youtube-iframe" ).invoke( "setStyle", {visibility: "visible"} );
			
			},
			
			onFinish: function () {
			
			    $( "sb-wrapper-inner" ).setStyle( {
				
				    height: 0,
					display: "block"
					
				} );
			
			}
			
		} );
	}
	
}


