window.addEvent( 'domready', function(){
if (document.id('welcomebox'))
	{
	if(((navigator.userAgent.match(/iPhone/i)) ||
                (navigator.userAgent.match(/Android/i)) ||
                (navigator.userAgent.match(/iPod/i)))
		&&((location.host == 'www.sp-ps.ch')||(location.host == 'sp-ps.ch'))
		&&((location.pathname == '/fre') || (location.pathname == '/ger') || (location.pathname == '/'))
		)
        {
         lightbox = check_cookie();
    		}
    		else
    		{
    		  show_welcome_lb();
				}
	}
	else
	{
	  if (document.id('check_mobile'))
	  {
		  if(((navigator.userAgent.match(/iPhone/i)) ||
	                (navigator.userAgent.match(/Android/i)) ||
	                (navigator.userAgent.match(/iPod/i)))
			&&((location.host == 'www.sp-ps.ch')||(location.host == 'sp-ps.ch'))
			&&((location.pathname == '/fre') || (location.pathname == '/ger') || (location.pathname == '/'))
			)
	        {
	         lightbox = check_cookie();
	    		}
		}
	}
	document.id('check_mobile').getElements('a').addEvent('click',function(e)
			{
				    this.getParent('ul').getElements('li').removeClass('selected');
			  		this.getParent('li').addClass('selected');
			  		Cookie.write('site_version', this.getParent('#check_mobile').getElement('li.selected a').get('rel'));
			  		check_cookie();
			  		lightbox.close();
			  		e.stop();
			});
});

function check_cookie()
{
  if (!Cookie.read('site_version'))
    {
    	var lightbox = new NXC.LightBox( {'shadow' : true } );
			lightbox.setContent( 'check_mobile', false );
    	lightbox.open();
   		return lightbox;
		}
	else
		{
			if (Cookie.read('site_version') == 'mobile')
      	location.replace("http://mobile.sp-ps.ch/static/sencha/");
      show_welcome_lb();
      return false;
		}
}

function show_welcome_lb()
{
	var welcome_lb = document.id('welcomebox');
	if( $type( welcome_lb ) == 'element' ) {
			var lightbox = new NXC.LightBox( {
					'shadow' : true } );
			lightbox.setContent( 'welcomebox', false );
			var oldCookie = Cookie.read('welcomebox');
			if( oldCookie != 'hide' ){
				var newCookie = Cookie.write('welcomebox','hide');
				var getCookie = Cookie.read('welcomebox');
				if( getCookie == 'hide'){
					lightbox.open();
				}
			}
	}
}

