
var LURL = IURL + "html/" + language + "/";

var edit_mode = get_cookie("editMode");
var debug_mode = false;

var content_document = "";

var now_section = "";
var now_section_url = "";
var now_section_2 = "";
var now_section_url_2 = "";

var last_page_url = get_cookie("lastURL");
var read_more_url = 1;

var last_menu = new Array(5); //used for "BACK"-button
for(var i=1; i<=5; i++)	last_menu[i] = get_cookie("menu["+i+"]");
if (last_menu[1]=="0")last_menu[1] = default_menu;

var original_width, banner_on = get_cookie("ad");
if (get_cookie("user")!=0)show_banner();

if (edit_mode) load(IURL + "controlPanel.js"); 


// ::::::::::::::::: O N _ L O A D :::::::::::::::::  //Executes when the entire page has finished loading

window.onload=function(){
	
	window.onload;

	if (!IE || content_document.location.href.indexOf("/home_") > 0) Hide("fader");

	if (google_stats_id) load(IURL + "google_tracker.html", "stats");
	
	if (edit_mode) {
	
        load(IURL + "controlPanel.html", "controlPanel");
	    load(IURL + layout + "/editors.html", "editors");
	    Hide2("back_button");
	}
	
	if (debug_mode) {
	    whenLoaded("controlPanel", "Show2('divSave');");
	}
}

window.onunload=function() {

    try {
        advancedEditor.HTMLeditor.SetHtml(""); 
        advancedEditor.blur();
    } catch(e) {}
}

function onContentLoaded(doc) { //content (HTML-files) are loaded into the content-iframe

    if (log_on && !edit_mode) {
        var url = doc.location.href.substr(BURL.length);
		load(BURL + "system/control/stats/log.asp?url=" + url);
	}

    content_document = doc; 
    
    if (doc.location.href.indexOf("login") < 0) {   //save last url only if not the login-page
        set_cookie("lastURL", doc.location.href);        //the last url is used by login and other pages.
        last_page_url = doc.location.href;
    } 
    
    if (edit_mode) whenLoaded("controlPanel,editors", "viewEditMode();");  
}


// :::::::::::::::::::::: G O ::::::::::::::::::::::  //Executes when user click on the main menu
			   
function go(url){

	url = url.replace(/new:/gi,BURL);

	if (edit_mode && lC(url).indexOf("system/modules") >= 0) { // Open Modules in separete window during edit Mode

		WIN.open(BURL + url, "module_" + rN());

	} else if (url.indexOf("://") > 0)	{	

		WIN.open(url, "win2");				//Open External links in a new window.

	} else { 

	    url = BURL + url;
	    if (edit_mode) url += "?r=" + gT(); //Adds a new number to prevent caching in edit mode
	    ajax(url, "gE('content').src = u;"); //loads page only if it exists (the ajax-function shows a alert-box otherwise)
    }
	
	Hide("Sub1,Sub2");							//Hide any submenus when an option is chosen.
}

function set_content(u) {
	URL = URL.replace(/page=/gi, "");	//for bacward compatibility (external pages link to wedran.com/?page=cube
	var i = URL.indexOf("?")+1;						//open anything after "?" in the content IFRAME
	if (i>0) u = BURL + URL.substr(i);
	if (gE("content").src != u) gE("content").src = u;
}

function go_home(l) { //l = language
    var url = BURL;
    if (!l) l = language;
    if (l != default_language)      
		url += l + "/";    //wedran.com/se/
	else  
		url += "?home_" + default_language;		//because of wed.Location (line can be skipped otherwise)
    if (layout != default_layout)   url += layout;     //wedran.com/se/basic
    WIN.location = url;
}


// ::::::::::::::::::::: S E T :::::::::::::::::::::

function set_layout(l) {
    if (!l || l=="") l = default_layout;
    layout = l;
}

function set_language(l) {
    if (!l || l=="") l = default_language;
    language = l;
}

function set_info(i) { 
    info = unescape(i);
	apply("info");
	set_txt("info", i);
	play("info");
}

function set_slogan(s)	{ 
	slogan = unescape(s);
	filter("logo", "Stretch(stretchstyle=PUSH)");
	play("logo");
	apply("slogan");
	set_txt("slogan", s);
	setTimeout("play('slogan');",500);
}

function set_photo(p) { 
    photo = p;
    if (!p || p=="") p = "s.gif";
	apply("photo");
	set_img("photo", "../i/photo/" + p);
	play("photo");
}

function set_logo(l) { 
    logo = l;
	if (!l || l=="") {
		Hide("personal");
	} else {
		set_img("personal", "../i/logo/" + l);
		Show("personal"); 
	}
}

function set_theme(t) { 
    theme = t;
	var i = t.split(",");
	if (i.length==1) i = t;else i= i[rN(i.length-1)];
	apply("theme");
	set_img("theme", "../i/theme/" + i);
	play("theme");
}

function set_background(b) {
    background = b;
    if (b=="")b="s.gif";
	set_img("back", "../i/background/" + b);
}

function set_news(n) {
    news = unescape(n);
	filter("news", "GradientWipe(GradientSize=0,wipestyle=1,motion=reverse);");
	set_txt("news", "<A HREF='" + NEWS_URL + "' TARGET=content>" + NEWS_TITLE + ":</A> <A HREF='" + NEWS_URL + "' TARGET=content STYLE='color:gray; text-decoration:none;'>" + n + "</A>");
	play("news");
	setTimeout("hide_news()",12000);
}

function set_ad(a) {
    
    if (!a) a == "";
    ad = a;
    
	if (a == "no") {
		hide_banner();
	} else if (a == "") {	//If no ad is specified then retreive previous state from cookie value
		if (banner_on != 0)
		    hide_banner(); 
		else
		    set_ad("yes");
	} else {
		if (lC(a) == "yes") ad = default_ad;
		show_banner();
		Show2("div_ad");
		if (isE("div_ad")) load(IURL + ad + "?r=" + gT(), "div_ad");
	}
}

function set_fastmenu(f) {

	fastmenu = f;

	if (f != "") {
		go_fastmenu();
		if (isE("shortcuts")) load(BURL + f + "?r=" + gT(), "shortcuts");
	}
}

// ::::::::::::::: S E T _ T I T L E :::::::::::::::

function set_title(t)	{ 
	title=t; 
	set_txt("content_title", "");
	setTimeout("set_title_2('"+t+"')",400);
}

function set_title_2(t)	{ 
	var tmp = t.split(","); 
	var section = "<A class=_title HREF=\"javascript:go('" + tmp[0] + "');\">" + tmp[0] + " \\ </A>";
	tmp = "<A class=_title HREF=\'javascript:go_home();\'>" + HOME_TITLE + "</A> \\ ";
	
	if (now_section_2 != null && now_section_2 != "") 
	    tmp += "<A class=_title HREF=\"javascript:go('" + trim(now_section_url_2) + "');\">" + now_section_2 + "</A> \\ ";
	else
	    now_section_2 = "";
	    
	if (now_section != null && now_section != "") 
	    tmp += "<A class=_title HREF=\"javascript:go('" + trim(now_section_url) + "');\">" + now_section + "</A> \\ ";
    else
	    now_section = "";
	    
	apply("content_title");
	set_txt("content_title", tmp + "<FONT STYLE='color:gray;'>" + t + "</FONT>"); 
	play("content_title");
}

function set_section(s) {
    section = s;
	last_menu_url = now_section_url;
	var tmp = s.split(","); 
	now_section = tmp[0];
	now_section_url = tmp[1];
	now_section_2 = tmp[2];
	now_section_url_2 = tmp[3];
}

// :::::::::::::::::::: H E L P ::::::::::::::::::::

function help(n,o,y,x) { //n=help number/index, o=object (optional) eg. this where the helpbox will retreive X & Y coordinates. Y and X are optional parameters if the o is null.

	hide_help();
	
	var t=n;
	if (!isNaN(n)) t=HELP[n];
	
	if (o) {
	    y = o.style.top;
	    x = o.style.left;
	} else if (!y) {
	    y = getHY(n);
	    x = getHX(n);
	}
	
	apply("help_box");
	set_txt("help_text", t);
	gE("help_box").style.top = y;
	gE("help_box").style.left = x;
	Show("help_box");
	play("help_box");
}

function hide_help() {
	Hide("help_box");
}