/*
*	Custom functions to handle partial content display in divs
*/
var content_folder = "";
if(typeof logged_in == "undefined") 
{
	// first load
	var logged_in = false;
}

function getContentURL(page) {
	var url = "";
	
	if(page.indexOf(".") != -1) {		// a whole page url is passed
		return page;					// just return the same string
	}
	
	switch (page){
	case "about":
		url = "content/about.html";
		break;
	case "agency":
		url = "content/agency.html";
		break;
	}
	return content_folder + url;
}

// CALLED FROM FLASH
function flashArea(params_obj)
{
/*	var s = "";
	for(var m in params_obj){
		s += m+"  "+params_obj[m]+"\n";
	}
	alert(s)
*/	
	var h = new HTMLArea({ 
		id:params_obj.id, 
		
		left:params_obj.x, 
		top:params_obj.y,
		 
		width:params_obj.w, 
		height:params_obj.h,
		
		content:getContentURL(params_obj.url), 
		content_type:"url",
		
		scroll:params_obj.scroll,
		scrollclass:params_obj.scrollclass
	});
}
function removeArea(id)
{
	var a = getAreaById(id);
	if(a != null) a.remove();
}
function hideArea(id)
{
	var a = getAreaById(id);
	if(a != null) a.hide();
}
function moveAreaY(id, y)
{
	var a = getAreaById(id);
	if(a != null) {
		a.moveY(y);
		trace("moveAreaY:: "+id +" -> "+ y);
	}
}

function updateFlashHeights(area_id, area_height) {
	trace("updateFlashHeights:: "+area_id +" -> "+ area_height);
	$(".mainflashembed").each(function(){ 
		this.updateHeights(area_id, area_height);
	});
}

var prev_h=0;
function changeFlashStageHeight(h)
{
    //alert(prev_h+" -> "+h)
    prev_h = h;
	$(".mainflashembed").height(h);
}

function trace(msg)
{
	if(typeof console != "undefined") {
    	console.log(msg);
	}
}

function corporateDetails(url)	// called from corporate side menus
{
	updateArea("corporatetext_area", url);
}
function refreshAfterLoad(iframe_body_tag_html, area_id)
{
	var html = iframe_body_tag_html;
	updateArea(area_id, html, true);
}

/* utils */
function getVar(name){
	var str = document.location.href;
	if (str.indexOf("?") != -1){
		if(str.indexOf("#") != -1) {
			str = str.split("#")[0];
		}
		arr = str.split("?")[1].split("&");
		for (var i=0; i<arr.length;i++){
			if (arr[i].split("=")[0] == name) return unescape(arr[i].split("=")[1]);	
		}
	}
	return "";
}



/*************************************
              PORTFOLIO
**************************************/
function loadSolutionsList() {
    $("#solutions_list_td").html("loading...");
    $("#solutions_list_td").load("GetSolutions.aspx?" + "rand=" + Math.random());
}
function loadIndustriesList(solution,id)
{
    $("#industries_list_td").html("loading...");
    //$("#industries_list_td").load("GetIndustries.aspx?Solution=" + solution + "&ID=" + id + "&rand=" + Math.random());
    $.get("GetIndustries.aspx?Solution=" + solution + "&ID=" + id + "&rand=" + Math.random(), function(data) {
        $("#industries_list_td").html(data);
    });
}
function loadPortfolioPages(id, solution) 
{
    loadPortfolioHighlights(id, solution);
    loadPortfolioList(id);
}
function loadPortfolioDetailPages(id) {
    loadPortfolioDetails(id);
    loadPortfolioList(id);
}
function loadPortfolioHighlights(id, solution)
{
    updateArea("cont2_mc_area", "Portfolio.aspx?ID=" + id + "&Solution=" + solution + "&rand=" + Math.random());
}
function loadPortfolioList(id)
{
    updateArea("cont3_mc_area", "ProjectListing.aspx?ID=" + id + "&rand=" + Math.random());
}
function loadPortfolioDetails(id) {
    updateArea("cont2_mc_area", "ProjectDetails.aspx?PageID=" + id + "&rand=" + Math.random());
}
function LoadImage(url) {
    $(".imgMain").attr("src",url);
}


// fake login
function onLoginSubmit() 
{
	$("#login_msg").hide();
	$("#login_loader").show();
	window.setTimeout(function(){ $("#login_msg").show(); $("#login_loader").hide(); }, 1500);
}

// popups
function popup(url) 
{ 
  window.open(url,"win","scrollbars=yes,width=630,height=400");
}

/*
    AWARDS
*/
function changecompetition() {
    var val = $("#comp").val();
    if(val == "Panarab Web Awards") {
        $("#panarab").show();
        $("#lebanon").hide(); 
    } else {                 
        $("#panarab").hide(); 
        $("#lebanon").show(); 
    }
}

/*
    JOBS
*/
var active_job = "";
function setJob (job) 
{
    switch (job){
        case "designers":
            active_job = "Web Designers/Art Directors"
            break;
        case "sales":
            active_job = "Sales Officers"
            break;
        case "developers":
            active_job = "Web Developers"
            break;
        case "producers":
            active_job = "Web Producers"
            break;
        case "flash":
            active_job = "Flash Designers/Animators/developers"
            break;
    }
}


$(document).ready(function() {
    if(typeof is_homepage == "undefined") {
        if($(".RadEditor").length == 0) {
            // hide actual html page content (it'll be shown latter in flash)
            $(".areacontent").hide();
            // extract the page id from the url and set it as hash
            document.location.hash = getVar("pageid");
        } else {
            // edit mode => hide flash
            $(".mainflashembed").hide();
        }
    }
});


