/*

var mm__fade_interval = -1;
var mm__cb_arr = ['',''];
var mm__fade_obj;
var mm__fade_alpha = 0;
var mm__fade_alpha_step = 10;
var mm__fade_frame_millseconds = 5;
var mm__fade_dir = 0;


function mm__fadeIn(div_obj, cb_arr){
	mm__cb_arr[0] = cb_arr[0];
	mm__cb_arr[1] = cb_arr[1];
	clearInterval(mm__fade_interval);	
	mm__fade_obj = div_obj;
	mm__fade_alpha = 0;
	setAlpha(mm__fade_obj,mm__fade_alpha);	
	mm__fade_dir = 1;	
	mm__fadeFrame();
}

function mm__fadeOut(div_obj, cb_arr){
	mm__cb_arr[0] = cb_arr[0];
	mm__cb_arr[1] = cb_arr[1];
	clearInterval(mm__fade_interval);	
	mm__fade_obj = div_obj;
	mm__fade_alpha = 100;
	setAlpha(mm__fade_obj,mm__fade_alpha);	
	mm__fade_dir = -1;	
	mm__fadeFrame();
}

function mm__fadeFrame(){

	mm__fade_alpha+=(mm__fade_alpha_step*mm__fade_dir);
	
	if (mm__fade_dir>0){
		mm__fade_alpha = Math.min(100,mm__fade_alpha);
	} else if (mm__fade_dir<0){
		mm__fade_alpha = Math.max(0,mm__fade_alpha);
	}
		
	setAlpha(mm__fade_obj, mm__fade_alpha)
	
	if ((mm__fade_dir>0 && mm__fade_alpha == 100) || (mm__fade_dir<0 && mm__fade_alpha == 0) ){
		
		if (mm__cb_arr.length > 0 ){
			if (mm__cb_arr[0].length > 0 ){
				eval(mm__cb_arr[0] + "('" +mm__cb_arr[1]+"')" );
			}
		}
	
	} else {
	
		mm__fade_interval = setTimeout("mm__fadeFrame()",mm__fade_frame_millseconds);
		
	}
}


function setAlpha(obj_ref, percentage) {
		if (obj_ref.filters && obj_ref.filters[0]) {
			if (typeof obj_ref.filters[0].opacity == "number") { //if IE6+
				obj_ref.filters[0].opacity = percentage;
			} else { //else if IE5.5-
				obj_ref.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity="+percentage+")";
			}
		} else if (obj_ref.style.MozOpacity) {
			obj_ref.style.MozOpacity = percentage / 101;
		} else if (obj_ref.style.KhtmlOpacity) {
			obj_ref.style.KhtmlOpacity = percentage / 100;
		}
	}
	*/
// <div style="zoom: 1; margin-top: 0px; filter:progid:DXImageTransform.Microsoft.Alpha(opacity=100);-moz-opacity:100;-khtml-opacity:100;" 

// -----------------------------------------------------------------------------------------------------------------------------------------

//document.getElementsByTagName("body").item(0).style.cursor = "wait";

var req;
var js_dynamic = -1;
var str_js_object_list = "";
var obj_flash_content = new Object();
var str_flash_content = "";
var bln_is_flash = true;
//var body_alpha = 0;
  




/* Page loading
===========================================================*/


function loadXMLDoc(url) 
{        


    // Kill cache
    var ck = Math.round(Math.random() * 8999)+1000;
    if (url.split("?").length < 2){
        url+="?ck=" + ck;
    } else {
        url+="&ck=" + ck;
    }   
	//alert("!!"); 
	//prompt("?" , url);   
	
    if (window.XMLHttpRequest) {
        // branch for native XMLHttpRequest object
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;   
        req.open("GET", url, true);
        req.send(null);        
    } else if (window.ActiveXObject) {
        // branch for IE/Windows ActiveX version
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET", url, true);
            req.send();
        }
    } else {
        // Error
        redirectToStaticSite();    
    }
}
    
    
    
	
	
function processReqChange() 
{
    // only if req shows "complete"
    if (req.readyState == 4) {
    
        // only if "OK"
        if (req.status == 200) {
        
            //var xml_response = req.responseXML.documentElement;            
            // convert the string to an XML object
            var str_response_text = req.responseText;        
            var xml_response;
            
            if (window.ActiveXObject)
            {
                
				// code for IE
                xml_response= new ActiveXObject("Microsoft.XMLDOM");
                xml_response.async="false";
                xml_response.loadXML(str_response_text);
				
            } else {
			    
				// code for Mozilla, Firefox, Opera, etc.   
                var parser=new DOMParser();
                xml_response=parser.parseFromString(str_response_text,"text/xml");
				
            }            
			// Reset the pagination current page
			int_currently_visible_pagination_div = 1; 
			            
            //var str_success = String(xml_response.getElementsByTagName('response')[0].attributes["success"].nodeValue);
			
			var node_response = xml_response.getElementsByTagName('response')[0];
			
			var str_success = getAttributeVal(node_response, "success");
			
			if (str_success != "1" ){
				 redirectToStaticSite();    
				 return;
			}
			
			//="content/background-script.js" ="test12323423423423,temp_function,populateSideImageWithRandomPic"
			
            // Set body text -  
            if (e("body-content-div")){       

				// Unload of javscript objects if any
				if (js_dynamic != -1){
					document.getElementsByTagName("head")[0].removeChild(js_dynamic);
					js_dynamic = -1;
					if (str_js_object_list.length > 1){
						var arr_del_js_objects = str_js_object_list.split(",");
						for( var i = 0; i < arr_del_js_objects.length ; i++){
							if (arr_del_js_objects[i] != "e"){   
								var tmp_js_obj = eval("window." + arr_del_js_objects[i] );
								if (tmp_js_obj){ 
									if (typeof(tmp_js_obj) == "function"){			
										eval("window." + arr_del_js_objects[i] + "=null" );
										//tmp_js_obj = null;					
									}
								}
							
							}
						}
					}
					str_js_object_list = "";
				}


				var bln_any_bodycontent = false;
				
				if (getAttributeVal(node_response, "any_bodycontent") == "1"){
					bln_any_bodycontent = true;
				}
				
				
				
				obj_flash_content = new Object();
				//flash_swf_path="image-gallery.swf" flash_xml_path="image_gallery-COMP071155AMPbTqfA.xml" flash_x="0" flash_y="0" flash_embed="1"
				if (getAttributeVal(node_response, "flash_embed") == "1"){
					obj_flash_content["flash_embed"]=true;
					obj_flash_content["flash_swf_path"]=getAttributeVal(node_response, "flash_swf_path");
					obj_flash_content["flash_xml_path"]=getAttributeVal(node_response, "flash_xml_path");
					obj_flash_content["flash_x"]=getAttributeVal(node_response, "flash_x");
					obj_flash_content["flash_y"]=getAttributeVal(node_response, "flash_y");
				} else {
					obj_flash_content["flash_embed"]=false;	
				}
				
				
				
				
				
				if (!bln_any_bodycontent){
					// Tell flash content is revealed.
					// alert("no html content");
					//onPageContentRevealed();	
					onPageContentLoaded(false);	
					return;
				}

				
				// Offset / reset body content.			
				// 
				
				var int_offset_top;
				if (getAttributeVal(node_response, "offset_htmlbody") == "1"){
					int_offset_top =  getAttributeVal(node_response, "offset_top") ;
					int_offset_top = Number(int_offset_top);
					if (isNaN(int_offset_top)){
						int_offset_top = 0;	
					}
				} else {
					int_offset_top = 0;
				}
				
				// Apply top offset - int_offset_top
				// <div id="body-content-div" style="display:block;overflow:hidden;left:190px;top:80px;width:610px;height:520px;position:absolute;"  >
				 e("body-content-div").style.top = String( 80 + int_offset_top ) + "px";
				 e("body-content-div").style.height = String( 520 - int_offset_top ) + "px";
				 
				
				
				
				
				// Get body content
				var str_bodytext = xml_response.getElementsByTagName('bodytext')[0].firstChild.data;
												
												
												
				
												
												
				// Load content
                e("body-content-div").innerHTML = str_bodytext;  		
				
				
			
				// Process alpha pngs for IE6	
				if (bln_is_IE6){
					 setTimeout("processAlphaPNGSforIE6()",3);
				} 
				
				

				//if( String(navigator.userAgent.toLowerCase()).split('safari').length > 1 ){ 
			 	//	setTimeout("fixSafari()",100);				
				//}
				
				// Now load javscript if required
				
				//String(xml_response.getElementsByTagName('response')[0].attributes["bln_jsfile"].nodeValue);
				
				var str_bln_jsfile = getAttributeVal(node_response, "bln_jsfile"); 
				
				if (str_bln_jsfile == "1" ){
				
					var str_jsfile_path = getAttributeVal(node_response, "jsfile_path");  //String(xml_response.getElementsByTagName('response')[0].attributes["jsfile_path"].nodeValue);
					str_js_object_list = "";
					str_js_object_list = getAttributeVal(node_response, "js_objects"); //String(xml_response.getElementsByTagName('response')[0].attributes["js_objects"].nodeValue);
					
					js_dynamic = document.createElement("script");
					js_dynamic.exists = true;
					js_dynamic.setAttribute("type", "text/javascript");
					js_dynamic.setAttribute("src", str_jsfile_path);
					document.getElementsByTagName("head")[0].appendChild(js_dynamic);
									
				}
            }    
			
					
			// Make callback			
			onPageContentLoaded(true);
						            
        } else {
            // Error
            redirectToStaticSite();    
        }
    } 
}    

//function fixSafari(){
	//alert("Safari");	
//}


function getAttributeVal(node, str_attribute_name){				
		var str_attribute_val = "";
		for( var x = 0; x < node.attributes.length; x++ ) {
			  if( node.attributes[x].nodeName.toLowerCase() == str_attribute_name ) {
				str_attribute_val = node.attributes[x].nodeValue;
				break;
			  }
		}
		return str_attribute_val;
}
// ----------------------------------------------------------------------------------

/*
var js = -1;
function addScript(jsFile){
	js = document.createElement("script");
	js.exists = true;
	js.setAttribute("type", "text/javascript");
	js.setAttribute("src", jsFile);
	document.getElementsByTagName("head")[0].appendChild(js);
}
function test(){
	addScript("scripts/test.js");
}

function testdispose(){
	if (js != -1){
		window.populateSideImageWithRandomPic = null;
		document.getElementsByTagName("head")[0].removeChild(js);
		
		js = -1;
	} else {
		alert("NO JS");
	}
}
*/
// ----------------------------------------------------------------------------------


function onPageContentLoaded(bln_html_content){

	//alert("onPageContentLoaded(content?" + bln_html_content);
	// Check if flash content is required.
	//var bln_flash_content = false;
	
	if (bln_html_content){
		fadeInContent(["onPageContentRevealed"]);
	} else {
		 onPageContentRevealed()
	}

}



function onPageContentRevealed(){
	// prop_one_~_prop_val___prop_two_~_val_two
	var $str_flash_content = "";
	for (var p in obj_flash_content){
			if ($str_flash_content.length > 0){
				$str_flash_content+="___";
			} 
			$str_flash_content+=p+"_~_"+obj_flash_content[p];
	}
	str_flash_content = "";
	str_flash_content = $str_flash_content ;
	
	setTimeout("onPageContentRevealed__2()",5);
} 

function onPageContentRevealed__2(){
	
	if (getFlashObjectById('main_flash')){

	getFlashObjectById("main_flash").onPageContentLoaded__js_to_flash(str_flash_content);	
	}	
}

function loadPageByUid(str_page_uid){
	
	var obj_page_request = new Object();
	obj_page_request["page_uid"] = str_page_uid;	
	getFlashObjectById("main_flash").loadPage__js_to_flash(obj_page_request);	
}


/*

function fadeInContent(){
	body_alpha+=10;
	if (body_alpha > 100){
		body_alpha = 100;
	}
	setAlpha(e("body-content-div") , body_alpha );
	if (body_alpha < 100){
		setTimeout("fadeInContent()",5);
	} else {
		getFlashObjectById("main_flash").onPageContentLoaded__js_to_flash(true);
	}
}

function fadeInContent(){
	body_alpha+=10;
	if (body_alpha > 100){
		body_alpha = 100;
	}
	setAlpha(e("body-content-div") , body_alpha );
	if (body_alpha < 100){
		setTimeout("fadeInContent()",5);
	} else {
		getFlashObjectById("main_flash").onPageContentLoaded__js_to_flash(true);
	}
}

*/

    
	/*
function debug(str){
    if(e("debug")){
        e("debug").innerHTML+= str;
    }
} */
 

function redirectToStaticSite(){
	//alert("e r r o r");
    window.location = "static/";
}

function getFlashObjectById(str_id){
	if(navigator.appName.indexOf("Microsoft") != -1) {
		obj_flash = window[str_id];
	}else {
		obj_flash = window.document[str_id];
	}
	return obj_flash;
}

// FUNCTION CALLS FROM FLASH :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::



function loadPageContent__flash_to_js(obj_page_request){
	loadXMLDoc("GetPageContent.aspx?page="+obj_page_request["page_uid"]+"&force_update=0" );
}


function hidePageContent__flash_to_js(){ 	
	
	fadeOutContent(["onPageContentHidden"]);
}


function onPageContentHidden(){
	
	
	
		setTimeout("getFlashObjectById('main_flash').onPageContentHidden__js_to_flash()" , 10); 
	
}
 

 

cb_arr__fadeOutContent = new Array();
function fadeOutContent(cb_arr){
	// Save callback
	for (var i = 0 ; i < cb_arr.length ; i++){
		cb_arr__fadeOutContent[i] = cb_arr[i]
	}
	// If already hidden return;
	if(e("body-content-container-div")){
		if (e("body-content-container-div").className=="hide"){
			makeCallBack(cb_arr__fadeOutContent);
			return;
		} 
	} 
	// Simple flick
	if(e("body-content-container-div")){
		e("body-content-container-div").className="hide";
	}  
	makeCallBack(cb_arr__fadeOutContent);
}



cb_arr__fadeInContent = new Array();
function fadeInContent(cb_arr){
	// Save callback
	for (var i = 0 ; i < cb_arr.length ; i++){
		cb_arr__fadeInContent[i] = cb_arr[i]
	}			
	// Simple flick
	if(e("body-content-container-div")){
		e("body-content-container-div").className="show";
	}  
	makeCallBack(cb_arr__fadeInContent);
}


function makeCallBack(cb_arr){
	if (cb_arr.length < 1 ){
		return;
	} else if (cb_arr.length == 1) {
		cb_arr[1] = "";
	}
	eval(cb_arr[0] + "(" + cb_arr[1]+ ")");
}


function setPageTitleAndHashAddress__flash_to_js(str_page_title, str_page_uid){

	

	if (bln_hash_history_not_iframes){
	
		var str_hash = String(window.location.hash);
		if (str_hash.split("#").join("") == str_page_uid){
			//alert("HASH LEFT");
		} else {	
			bln_ignore_next_hash_change = true;
			window.location.hash = str_page_uid;
		}
	} else {
		window.location.hash = str_page_uid;
	}
	setTimeout("setPageTitle(\"" +str_page_title+"\")" , 100);
}
 
function setPageTitle(str_title){

	document.title="QT Kids - Queensland Government - " + str_title;
	
}


function savePageRequestStringToHistory__flash_to_js(str_page_request_string, str_connection_id, str_page_title){
	//alert("savePageRequestStringToHistory__flash_to_js");
	if (e("history_frame")){		
		
		e("history_frame").src = "History.aspx?remote_connection_id=" + str_connection_id + "&page_request_string=" + str_page_request_string + "&str_title=" + str_page_title;
		//alert("SET HISTORY FRAME " + e("history_frame").src);
	} else {
		//alert("ERROR: NO HISTORY FRAME");	
	}
}   


if (bln_hash_history_not_iframes){

	var str_last_hash = "";
	var bln_ignore_next_hash_change = true;
	var int_timeout_id = -1;
	function checkForHistoryHashChange(){
		
		var str_current_hash = window.location.hash
		 
		if (str_current_hash != str_last_hash){
			//alert("HASH has changed - was " + str_last_hash + " now " + str_current_hash + " ->");
			if (bln_ignore_next_hash_change){
				//alert("->ignored");
				bln_ignore_next_hash_change = false;								
				
			} else {
				//clearInterval(int_timeout_id);
				// Format : "prop_one_~_prop_val___prop_two_~_val_two"	
				//alert(str_current_hash);
				getFlashObjectById("main_flash").loadPageFromHistory__js_to_flash("page_uid_~_" + str_current_hash.split("#").join("") );					
				//alert("->GO TO HISTORY PAGE " + str_current_hash);
			}
			
			str_last_hash = str_current_hash;
		}		
		
		
		//int_timeout_id = setTimeout("checkForHistoryHashChange()" , 100);
	}
	
	
	int_timeout_id = setInterval("checkForHistoryHashChange()" , 500);
	//checkForHistoryHashChange();

}




