var getUrl = '';
var urlArray = [];
var obj1 = '#fade_image1';
var obj2 = '#fade_image2';
var interrupt = false;
var fading = true;
var TinyMceActivated = false;
var showQueue = new Array();

jQuery(document).ready(function()
{
	// Create dropdown menu
	jQuery('#dropdown').ptMenu();
	// Fade and change the header img
	setImage(fadingImages,0,true);
	// Load the availability widget
	loadAvailabilityWidget();
	// Load the accommodation widget
	loadAccommodationWidget(12000, true);
});

function setLanguageText()
{
	var lang = (!get('lang') ? defaultLanguage : get('lang'));
	jQuery.each(languageArray[lang],function(i,item)
	{
		if(jQuery('.langItem'+i).hasClass('button'))
		{
			jQuery('.langItem'+i).html(item);
		}
		else
			jQuery('.langItem'+i).text(item);			
	});
	
	jQuery.datepicker.setDefaults(jQuery.datepicker.regional[(!get('lang') ? defaultLanguage : get('lang'))]);
	
	switch(lang)
	{
		case 'nl':
		{
			jQuery.extend(jQuery.validator.messages,
			{
				required: "Dit veld is verplicht.",
				maxlength: jQuery.format("U kunt niet meer dan {0} karakters invoeren."),
				minlength: jQuery.format("U dient minimaal {0} karakters in te voeren."),
				rangelength: jQuery.format("U dient minimaal {0} en maximaal {1} karakters in te voeren."),
				email: "Voer alstublieft een geldig e-mail adres in.",
				url: "Voer alstublieft een geldig web adres in.",
				date: "Voer alstublieft een geldige datum in.",
				number: "Voer alstublieft een geldig getal in.",
				digits: "Gebruik alleen cijfers.",
				equalTo: "Herhaal de invoer nogmaals.",
				range: jQuery.format("U dient een waarde tussen {0} en {1} in te voeren."),
				max: jQuery.format("U dient een waarde kleiner dan of gelijk aan {0} in te voeren."),
				min: jQuery.format("U dient een waarde groter dan of gelijk aan {0} in te voeren."),
				creditcard: "Voer alstublieft een geldig creditcard nummer in."
			});
			break;
		}
		case 'gb':
		{
			jQuery.extend(jQuery.validator.messages,
			{
				required: "This field is required.",
				remote: "Please fix this field.",
				email: "Please enter a valid email address.",
				url: "Please enter a valid URL.",
				date: "Please enter a valid date.",
				dateISO: "Please enter a valid date (ISO).",
				dateDE: "Bitte geben Sie ein gültiges Datum ein.",
				number: "Please enter a valid number.",
				numberDE: "Bitte geben Sie eine Nummer ein.",
				digits: "Please enter only digits",
				creditcard: "Please enter a valid credit card number.",
				equalTo: "Please enter the same value again..",
				accept: "Please enter a value with a valid extension.",
				maxlength: jQuery.format("Please enter no more than {0} characters."),
				minlength: jQuery.format("Please enter at least {0} characters."),
				rangelength: jQuery.format("Please enter a value between {0} and {1} characters long."),
				range: jQuery.format("Please enter a value between {0} and {1}."),
				max: jQuery.format("Please enter a value less than or equal to {0}."),
				min: jQuery.format("Please enter a value greater than or equal to {0}.")
			});
			break;
		}
		case 'de':
		{
			jQuery.extend(jQuery.validator.messages,
			{
				required: "Dieses Eingabefeld ist verpflichtet.",
				maxlength: jQuery.format("Sie k&ouml;nnen nicht mehr als {0} Zeichen eingeben."),
				minlength: jQuery.format("Sie sollen mindestens {0} Zeichen eingeben."),
				rangelength: jQuery.format("Sie sollen minimal {0} und maximal {1} Zeichen eingeben."),
				email: "Bitte geben Sie eine g&uuml;ltige E-Mail-Adresse ein.",
				url: "Bitte geben Sie eine g&uuml;ltige Internet-Adresse ein.",
				date: "Bitte geben Sie ein g&uuml;ltiges Datum ein.",
				number: "geben Sie eine g&uuml;ltige Zahl ein.",
				digits: "Bitte nur Zahlen eingeben.",
				equalTo: "Wiederholen Sie bitte Ihre Eingabe.",
				range: jQuery.format("Sie sollen eine Zahl von {0} bis {1} eingeben."),
				max: jQuery.format("Sie sollen eine Zahl kleiner als oder gleich {0} eingeben."),
				min: jQuery.format("Sie sollen eine Zahl gr&ouml;&szlig;er als oder gleich {0} eingeben."),
				creditcard: "DE Voer alstublieft een geldig creditcard nummer in."
			});
			break;
		}
		case 'ltu':
		{
			jQuery.extend(jQuery.validator.messages,
			{
				required: "&#352;is laukelis privalomas.",
				maxlength: jQuery.format("Negalite ivesti daugiau nei {0} &#382;enklu."),
				minlength: jQuery.format("Privalote ivesti ma&#382;iausiai {0} &#382;enklu."),
				rangelength: jQuery.format("Privalote ivesti ma&#382;iausiai {0} ir daugiausiai {1} &#382;enklu."),
				email: "Pra&#353;ome ivesti galiojanti el. pa&#353;to adresa.",
				url: "Pra&#353;ome ivesti galiojanti interneto adresa.",
				date: "Pra&#353;ome ivesti teisinga data.",
				number: "Pra&#353;ome ivesti teisinga skaiciu.",
				digits: "Naudokite tik skaicius.",
				equalTo: "Iveskite informacija dar karta",
				range: jQuery.format("Privalote ivesti verte nuo {0} iki {1}."),
				max: jQuery.format("Privalote ivesti verte, ma&#382;esne arba lygia {0} vertei."),
				min: jQuery.format("Privalote ivesti verte, didesne arba lygia {0} vertei."),
				creditcard: "LTU Voer alstublieft een geldig creditcard nummer in."
			});
			break;
		}
	}
}

// Function called when the processing of the url is done
function processingReady()
{	
	showAjaxLoader(2);
	
	// After processing, if get('admin') is set show the login form
 	if(get('admin',false))activateDialogWindow('edit_dialog','login');
 	
 	var lang = get('lang');
 	if(lang && lang != defaultLanguage && !get('edit',false))loadSiteMenu();
	
	jQuery.datepicker.setDefaults(jQuery.datepicker.regional[(!get('lang') ? defaultLanguage : get('lang'))]);
	
	// If extend processing is defined, execute it
	if(typeof extendProcessingReady != 'undefined')extendProcessingReady();	
}

function loadBooking()
{
	jQuery('#booking').load('/modules/booking/index.php','',function(){});	
}

function loadAvailabilityWidget()
{
	jQuery.getJSON('/load.php',{accommodations : 'all', language : (!get('lang') ? defaultLanguage : get('lang'))},function(data)
	{
		jQuery.each(data,function(i,item)
		{
			jQuery('#accommodation_select').append('<option value="'+item.name+'">'+item.name+'</option>');
		});
		
		jQuery('#accommodation_select').change(function()
		{
			jQuery('#widget_datepicker').datepicker('destroy');
			createDatepicker();
		});
				
		createDatepicker();
	});
}

	var createDatepicker = function()
	{
		jQuery('#widget_datepicker').datepicker
		({
			showOtherMonths: true,
			beforeShow: function()
			{
				if(jQuery(this).datepicker('getDate') != null)
				{
					date = jQuery(this).datepicker('getDate');
					checkAvailability(jQuery('#accommodation_select').val(), date.getFullYear(), date.getMonth()+1);
				}
			},
			beforeShowDay: function(date)
			{
				return [false,''];
			},
			onChangeMonthYear: function(year, month, inst)
			{
				checkAvailability(jQuery('#accommodation_select').val(), year, month, '#widget_datepicker');
			}
		});
	}

// Function that checks the availability, and adds a 'ui-state-booked' class for the days that are booked.
function checkAvailability(accommodation, year, month, div)
{
	if(!isdefined(div))div = '#ui-datepicker-div';
	
	// Load the page (if no language is set, use the default language)
	jQuery.getJSON('/load.php',{availability : 'check', accommodation : accommodation ,year : year, month : month},function(data)
	{
		if(data.length > 0)
		{			
			// Check each datepicker date
			jQuery(div).find('.ui-state-default').each(function(i,item)
			{
				var element = jQuery(this);
				// Compare the current date, with dates from the loaded data
				jQuery.each(data,function(d,date)
				{
					// If the dates match, add a 'ui-state-boocked' class and break (return false) the loop
					if(date.day == element.html())
					{
						element.addClass('ui-state-booked');
						element.parent().attr('onclick','return false;');
						element.attr('onclick','return false;');
						return false;
					}
				});
			});
		}
	});
}

// Function that sets the obj image to a random src
function setImage(array, index, start)
{	
	var execute = function()
	{
		if(!interrupt && fading)
		{
			var _this = obj1;
			
			if(index == array.length) index = 0;
			
			jQuery(obj1).attr('src',array[index]).fadeIn(1000);			
			obj1 = obj2;
			index += 1;
			
			jQuery(obj2).fadeOut(1000);			
			obj2 = _this;
				
			// Recursive call of set image
			setImage(array, index);
		}
	}
	
	// If not interrupted, proceed as normal. Else load Google maps
	if(!interrupt && fading)
	{
		// If route map exists, fade it out and remove it
		if(jQuery('#route_map').exists())
		{
			jQuery('#route_map').fadeOut(1000,function()
			{
				jQuery(this).remove();
				execute();
			});
		}
		else
		{
			if(isdefined(start))
				execute();
			else
			jQuery(this).timeOut(8000,function()
			{
				execute();
			});
		}
	}
	else if(fading)
	{
		jQuery(obj1).parent().append
		(
				'<div id=\"route_map\">'
			+		'<iframe width=\"100%\" height=\"100%\" frameborder=\"0\" scrolling=\"no\" marginheight=\"0\" marginwidth=\"0\" src=\"http://maps.google.com/maps/ms?hl=nl&amp;ie=UTF8&amp;msa=0&amp;msid=117327317922011868682.00046b83e425a1d4a321d&amp;ll=55.103516,21.730957&amp;spn=2.841231,17.666016&amp;z=6&amp;output=embed\">'
			+		'</iframe>'
			+	'</div>'
		);
		
		/*if(GBrowserIsCompatible())
		{
			var map = new GMap2(document.getElementById('route_map'));
			map.addControl(new GMenuMapTypeControl(), new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(30,5)));
			map.addControl(new GSmallZoomControl3D(), new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(5,4)));
			map.setCenter(new GLatLng(37.4419, -122.1419), 13);
		}
		*/
		
		if(jQuery(obj1).is(':visible'))
			var obj = obj1;
		else
			var obj = obj2;

		jQuery(obj).dequeue().fadeOut(1000);
		jQuery('#route_map').fadeIn(1000);
	}
	
	if(!fading)fading = true;
}

function loadAccommodationWidget(TimeOut, start)
{
	if(!isdefined(start))
	{
		for(var i = 0; i < 3; i++)
		{
			setTimeout("jQuery('.widget_thumb"+(3-i)+"').fadeOut('fast');"+(i == 2 ? "setTimeout(\"loadWidget("+TimeOut+");\",1000);" : ""), i*1000);
		}
	}
	else
	{
		loadWidget(TimeOut);
	}
}

	var loadWidget = function(TimeOut)
	{
		jQuery('#thumb_holder').empty().load('/load.php?accommodation_widget=&language='+(!get('lang') ? defaultLanguage : get('lang')),function()
		{
			// Create lightbox galleries
			jQuery('.image_holder a').lightBox();
			
			for(var i = 0; i < 3; i++)
			{
				setTimeout("fadeIn("+(i+1)+","+TimeOut+");", i*1000);				
			}
		});
	}
	
	var fadeIn = function(i, TimeOut)
	{
		jQuery('.widget_thumb'+i).fadeIn('fast',function()
		{
			if(i == 3)
			{
				jQuery(this).timeOut(TimeOut,function()
				{
					loadAccommodationWidget(TimeOut);
				});
			}
		});
	}

// If Array.indexOf function does not exist (IE) create it
if(!Array.indexOf)
{
    Array.prototype.indexOf = function(obj)
	{
        for(var i=0; i<this.length; i++)
		{
            if(this[i]==obj)return i;
        }
    }
}

// Function to center the object
jQuery.fn.centerScreen = function()
{
	var obj = this;
	obj.css('top', jQuery(window).height()/2-this.height()/2);
    obj.css('left', jQuery(window).width()/2-this.width()/2);
    jQuery(window).resize(function(){obj.centerScreen();});
}

// Function that gives a delay on the object
jQuery.fn.timeOut = function(time, callback)
{
	if(!isdefined(callback))callback = function(){};
	var obj = this; 
    obj.queue(function(){setTimeout(function(){obj.dequeue();callback();}, time)});
};

// Function checks if element exists
jQuery.fn.exists = function()
{
	return jQuery(this).length > 0;
}

// Get & set current page plugin
function setCurrentPagePlugin(Plugin, callback)
{
	if(typeof callback == "undefined")callback = function(){};
	CurrentPagePlugin = Plugin;
	
	callback();
}
function getCurrentPagePlugin()
{
	return CurrentPagePlugin;
}

// Load dialog
function loadDialog(div,content_url,icon,name,callback,login,width)
{
	if (typeof callback == "undefined")callback = function(){};
	if (typeof width == "undefined")width = 700;
	
	setDialogWidth(div, width);
	jQuery('#'+div+'_content').empty().load(content_url,'',function(){callback();activateDialogWindow(div,login);});
	jQuery('#'+div+'_title').html(name);
	setDialogWindowIcon(div,icon+'.png','/img/framework/dialog_icons/'+icon+'.png');
}

function setDialogWidth(div, width)
{
	jQuery('#'+div).width(width);
}

// Activates the dialog window and deactivates the main menu
function activateDialogWindow(div,login)
{
	if(typeof login == "undefined" || login == null)
	{
		if(jQuery('#framework_menu').is(':visible'))
		{
			hideMainMenu();
		}	
	}
	showDialogWindow(div);
}

// Shows the dialog window
function showDialogWindow(div)
{
	scroll(0,0);
	showFade('fade', 0.7);
	jQuery('#'+div).centerScreen();
	jQuery('#'+div).mb_open();
}

// Hides the dialog window
function hideDialogWindow(div)
{
	jQuery('#'+div).mb_close();
	jQuery('#'+div).unbind();
}

// Set new dialog window icon
function setDialogWindowIcon(div, icon_name, icon_path)
{
	jQuery('#'+div).attr('icon',icon_name).find('.icon').attr('src',icon_path);
}

// Shows the ajax loader (position = 1 || 2)
function showAjaxLoader(position)
{
	switch(position)
	{
		case 1:
			//jQuery('#ajax_loader').css('margin-left','-'+(jQuery('#ajax_loader').width()/2)+'px').show('fast');
			jQuery('#ajax_loader').fadeIn('fast').timeOut(1200);
			break;
		case 2:
			//jQuery('#ajax_loader').css('margin-left','-'+((jQuery('#ajax_loader').width()/2)+107)+'px').show('fast');
			jQuery('#ajax_loader').fadeIn('fast').timeOut(1200);
			break;
	}
}

// Shows the site submenu
function showSubmenu(div)
{
	var slide_height = '30';
	//jQuery('#'+div).css('height', '0px').animate({height: slide_height+'px'},'fast');
}

// Hides the site submenu
function hideSubmenu(div)
{	
	if(jQuery('#'+div).is(':visible'))
	{
		//jQuery('#'+div).animate({height: '0px'},'fast',function(){jQuery('#'+div).hide();});
	}
}

// Shows the fade overlay
function showFade(div,transparency)
{
	if(jQuery('#'+div).exists() && jQuery('#'+div).is(':hidden'))
	{
		jQuery('#'+div).css('display','block').css('opacity', 0).fadeTo('fast', transparency);
	}
}

// Hides the fade overlay
function hideFade(div)
{
	if(jQuery('#'+div).exists() && jQuery('#'+div).is(':visible'))
	{
		jQuery('#'+div).fadeTo('fast', 0,function(){jQuery('#'+div).hide()});
	}
}

// Load the site menu
function loadSiteMenu(edit)
{
	if(!isdefined(edit))edit = false;
	// Get url
	var getUrl = '/load.php?main_menu=get&language='+get('lang');
	// If edit, add it to the getUrl
	if(edit) getUrl += '&edit';
	
	jQuery('#main_menu #dropdown').fadeOut('fast').empty().load(getUrl,function()
	{
		// Create the dropdown menu 
		jQuery(this).ptMenu();
		jQuery('.main_menu_item').address(function()
		{
			return jQuery(this).attr('href').replace('/strt', '');
		});
		jQuery(this).fadeIn('fast');
	});
}

// Load site submenu
function loadSiteSubmenu(div,parent_id)
{
	jQuery('#'+div).load('/modules/edit_page/load.php?item=submenu&id='+parent_id,'',function()
	{
		showSubmenu(div);
		
		// Set all sub items to have font-weight normal, and the active one to have font-weight bold
		jQuery('.sub_item').each(function()
		{
			jQuery(this).css('font-weight','normal');
			
			var split = jQuery(this).attr('id').split('sub_item');
			
			if(split[1] == currentPageID)
			{
				jQuery(this).css('font-weight','bold');				
			}
		});
	});	
}

// Function that loads the page and sets the content
function loadPage()
{
	//showAjaxLoader(2);
	
	// Hide and empty the page assets
	jQuery('#normal_content').hide('fast').empty();
	jQuery('#plugin_top').hide('fast').empty();
	jQuery('#plugin_bottom').hide('fast').empty();
	jQuery('#booking').hide('fast');
	
	if(jQuery('.mceEditor').css('display') == 'none')
		jQuery('.mceEditor').show();
	
	// Hide TinyMCE text area's
	jQuery('.tiny_mce_textarea').hide('fast');
	
	// Retrieve get_page and get_sub(page)
	var get_page	= get('page');
	var get_sub		= get('sub');
	
	if(!get_page)
	{
		// No page is set, use the homepage
		var page = homePage;
	}
	else if(!get_sub)
	{
		// No subpage is set, so load the set page
		var page = get_page;
	}
	else
	{
		// A page and subpage have been set, load the subpage
		var page = get_sub;
	}
	
	// Pages with a space in the name, have a _ in stead, so replace them
	page = str_replace('_',' ',page);
	
	if(page == 'beschikbaarheid')
	{
		jQuery.address.value('/lang/'+(!get('lang') ? defaultLanguage : get('lang'))+'/booking');
	}
	if(page == 'route')
	{
		interrupt = true;
		setImage(fadingImages,0);
	}
	else
	{
		if(interrupt)
		{
			interrupt = false;
			fading = true;
		}
		else
			fading = false;	
		setImage(fadingImages,0);
	}
	
	// After processing, if get('booking') is set, load the booking module
 	if(get('booking',false))
 	{
 		loadBooking();
 		jQuery.address.title(siteTitle + 'Boeken');
	}
	else
	{
		// Load the page (if no language is set, use the default language)
		jQuery.getJSON('/load.php',{page : page, language : (!get('lang') ? defaultLanguage : get('lang'))},function(page)
		{
			// Set the page title
			jQuery.address.title(siteTitle + URLDecode(page.name));
			
			jQuery('.main_menu_item').removeClass('active');
			jQuery('#page_'+page.id).addClass('active');
			
			currentPageID = page.id;
			textPosition = page.text_position;
			
			// Load the submenu
			/*
			if(has_children == 'true')
			{
				loadSiteSubmenu('submenu',id);
			}
			*/
			
			if(jQuery('#holder').is(':hidden'))
				showQueue[showQueue.length] = '#holder';
				
			if(jQuery('#widgets').is(':hidden'))
				showQueue[showQueue.length] = '#widgets';
			
			// Check if there is a page plugin
			if(page.plugin_id != -1)
			{
				// Ther is a page plugin, so load it
				jQuery.ajax
				({
		            type: 'GET',
		            url: '/modules/'+page.plugin_name+'/index.php',
		            data: '',
		          	success: function(data)
		          	{	          			
		          		if(textPosition == 'bottom')
		          		{
		                	// Set the page content
							setPageContent(page.content, function()
							{
								showQueue[showQueue.length] = '#plugin_top';
		                		jQuery('#plugin_top').html(data);
							});
		           		}
		           		else if(textPosition == 'top')
		           		{
		           			// Set the page content
							setPageContent(page.content, function()
							{
								showQueue[showQueue.length] = '#plugin_bottom';
		           				jQuery('#plugin_bottom').html(data);
							});
		           		}
		           		else
		           		{
		           			// Text Position is set to none
							showQueue[showQueue.length] = '#plugin_top';
		           			jQuery('#plugin_top').html(data);
				   	        
		           			jQuery('.mceEditor').hide();
		           		}
		      		}
				});
			}
			else
			{
				// Set the page content
				setPageContent(page.content, function()
				{
					setLanguageText();
					// After the setPageContent function is done show each item in the show queue
					jQuery.each(showQueue,function(i,item)
					{
						jQuery(item).show('fast');
					});
					// Empty showQueue
					showQueue = [];
					// When done hide the ajax loader
					jQuery('#ajax_loader').fadeOut('fast');
				});				
			}
		});
	}
}

// Function that sets the page content (page = page data(json))
function setPageContent(page_content, callback)
{
	jQuery.datepicker.regional[get('lang')];
	
	// Check if in edit mode
	if(!TinyMceActivated && !get('edit',false))
	{
		// Add the site content div to the show queue
		showQueue[showQueue.length] = '#normal_content';
		// Set the page content
		jQuery('#normal_content').html(stripslashes(URLDecode(page_content)));
		
		jQuery('#normal_content a').each(function()
		{
			if(jQuery(this).attr('rel') == 'lightbox')
				jQuery(this).lightBox();
		});
	}
	else
	{
		// DYNAMIC TINYMCE INSTANCES
		var ed = tinyMCE.get('page_content');
		
		// Set page content
		ed.setContent(stripslashes(URLDecode(page_content)));
				
		// If a page plugin is active, load the tab
		handlePluginTab();
	}
	
	// If a callback is set, execute it
	if(isdefined(callback))callback();
}

// Function that sets the new language
function setLanguage(language)
{
	// Set new lang, assamble the new url, reload page
	jQuery.address.value(set('lang',language,true));
	
	loadSiteMenu();
}

// Function that processes/extracts the url (used after reload)
function processUrl(url)
{
	// Set the getUrl variable to the given url
	getUrl = url;
	
	// If url is defined, transform the url string into an url array
	if(isdefined(url))urlArray = getUrl.split('/');
}

// Function that will return the value of the given item
function get(item, next)
{
	if(!isdefined(next))next = true;
	
	// The urlArray contains all the url items. If next is true, it looks as follows:
	// urlArray['page','2','product','5']
	// So the item name will always precede it's value
	// If next is false, we're looking for an item without a specific value
	
	// Check if the item exists in the urlArray
	if(in_array(item, urlArray))
	{
		if(next)
		{
			// If the item exists and next is true, fetch the item it's value
			return urlArray[urlArray.indexOf(item)+1];
		}
		else
			return true;
	}
	else
	{
		// If not, return false
		return false;
	}
}

// Function that will set the value of the requested item
// (if assemble is true, it will create a new url and return it)
function set(item, value, assemble, inFront)
{
	// If assemble isn't defined, it is false
	if(!isdefined(assemble))assemble = false;
	if(!isdefined(inFront))inFront = false;
	
	// The urlArray contains all the url items. If next is true, it looks as follows:
	// urlArray['page','2','product','5']
	// So the item name will always precede it's value
	// If next is false, we're setting an item without a value
	
	// Check if the item exists in the urlArray
	if(!in_array(item, urlArray))
	{
		if(inFront)
		{
			if(value != '')
				// If there is a value set it to the first item
				urlArray[0] = value;
			else
				// If there is no value remove the first item
				urlArray.splice(0,1);
			
			// Add the new item in front of the array
			urlArray.unshift(item);
		}
		else
		{
			// If the item doesn't exist create the item
			urlArray[urlArray.length] = item;
		}
	}
	
	if(!inFront && value != '')
	{
		// Set the item it's value
		urlArray[urlArray.indexOf(item)+1] = value;
	}
	
	if(assemble)
	{
		return assambleUrlArray();
	}
}

function assambleUrlArray()
{
	var newUrl = '';
	for(i in urlArray)
	{
		if(urlArray[i] != '')
			newUrl += '/'+urlArray[i];
	}		
	return newUrl;
}

// Adress event handlers
// To debug for search engine (without javascript) put .change event into .internalChange and empty .init
jQuery.address
	.init(function(event)
	{
		// When init, and 'strt' is in the url, replace it with a # for the functioning of the address script
		var initUrl = window.location.href;
	    if(initUrl.indexOf('strt') > -1)
	    {
	    	window.location.href = window.location.href.replace('strt','#');
    	}
	})
	.change(function(event)
	{		
		// After the reload process the new url
	    processUrl(event.value);
	    
	    // After processing, handle the page loading
		if(get('edit',false) && !TinyMceActivated && loggedIn == 'true')
    	{
    		// Activate edit mode and load the edit menu
			activateTopbar();
		}
	    else
	    {
	    	// Load the page
	    	loadPage();
    	}
	})
	.internalChange(function(event){})
	.externalChange(function(event)
	{
		// If the change is external, execute processing ready after processing
		processingReady();
	});