$(document).ready(function(){
	if ($("#lang_combo").length){
	    $("#lang_combo").css('background-color', "white");	    
	    
	    $("#nav_lang").click(function(){    	
	    	$("#lang_combo").slideToggle();
	    	
	    	if ($("#lang-arrow-down:visible").length){
	    		$("#lang-arrow-down").hide();
	    		$("#lang-arrow-up").show();
	    	}
	    	else{
	    		$("#lang-arrow-up").hide();
	    		$("#lang-arrow-down").show();
	    	}
	    });
	}
});

swbc={};
swbc.window_width=0;
swbc.window_height=0;
/*swbc.main_header_height=79;*/
swbc.main_header_height=50;
swbc.main_width=0;
swbc.main_height=0;
swbc.main_h_scrollbar_height=20;
swbc.main_footer_height=30;
swbc.columns=new Array();
swbc.column_width=370;
swbc.column_header_height=28;
swbc.column_footer_height=25;
swbc.column_v_scrollbar_width=10;
swbc.main_margin_left = 0;

swbc.home_init_window_sizes=function(){
	swbc.window_width=document.documentElement.clientWidth;
	swbc.window_height=document.documentElement.clientHeight;
	swbc.main_width=document.documentElement.clientWidth;	
	swbc.main_height=swbc.window_height-(swbc.main_header_height+swbc.main_footer_height+swbc.main_h_scrollbar_height);
	
	$("#swbc_main").css({"height":swbc.main_height+"px"});
	$("#header_r").css({"top":"0px","left":Math.round((swbc.main_width-900)/2)+"px"});
	$("#footer_r").css({"left":Math.round((swbc.main_width-900)/2)+"px"});
}

swbc.dialog_open=function(d_id,level){
	swbc.w_width=document.documentElement.clientWidth;
	swbc.w_height=document.documentElement.clientHeight;
	var dialog_screen=$("#dialog_screen");
	dialog_screen.css({"z-index":level});
	dialog_screen.show();
	var dialog=$("#dialog_"+d_id);
	var d_width=dialog.attr("d_width");
	var d_height=dialog.attr("d_height");
	if(d_height=="e"){d_height=swbc.w_height-140;}
	else{
		if(d_height>=(swbc.w_height-90))
			d_height=swbc.w_height-90;
	}
	var d_left=Math.round((swbc.w_width/2)-(d_width/2));
	var d_top=Math.round((swbc.w_height/2)-(d_height/2))-40;if(d_top<10)
	d_top=10;
	var z_index=level+1;
	dialog.css({"background-color":"#ffffff","top":d_top,"left":d_left,"position":"fixed","_position":"absolute","width":d_width+"px","height":d_height+"px","z-index":z_index});
	dialog.show();
}

swbc.dialog_close=function(d_id,level){ 
	var dialog=$("#dialog_"+d_id);
	
	var loading = $("#dialog_loading").html();
	dialog.html('<div class="dialog_loading">'+loading+'</div>');
	dialog.hide();
	
	if(level==2)
		$("#dialog_screen").hide();
	else
		$("#dialog_screen").css({"z-index":(level-1)});
}

swbc.dialog_static_close=function(d_id,level){ 
	var dialog=$("#dialog_"+d_id);
	dialog.hide();
	if(level==2)
		$("#dialog_screen").hide();
	else
		$("#dialog_screen").css({"z-index":(level-1)});
}



function activeColumnContent(){
	$('.image_massage a').lightBox();
}

function refreshTooltip(){
	$('[rel$=tooltip]').bind('mouseover', function(){
	    var theMessage = $(this).attr('content');
	    
	    if ((theMessage!=undefined) && (theMessage.length>0)){
		    $('<div class="tooltip">' + theMessage + '</div>').appendTo('body').fadeIn('fast');		
			
			$(this).bind('mousemove', function(e){ 
				$('div.tooltip').css({
					'top': e.pageY - ($('div.tooltip').height() / 2) - 5,
					'left': e.pageX + 15
				});
			});
	    }
	}).bind('mouseout', function(){
		$('div.tooltip').fadeOut('fast', function(){
			$(this).remove();
		});
	});
}

function counter(parentid){	
     	//alert(parentid);
		var maxLength = 140;
		var currentLength = $(parentid+" #status_textarea").val().length;
		
		var remaining = maxLength - currentLength;
		
		var counter   = $(parentid+" #t8m_counter");
		
		counter.text(remaining);
	
		if (remaining <= 0) {
			//counter.attr("class", "toomuch");
	    } else {
			//counter.attr("class", "");
		}
	
}

/*
function counter(parentid){	
		var maxLength = 140;
		var currentLength = $(parentid+" #status_textarea").val().length;
		var remaining = maxLength - currentLength;
		
		var counter   = $(parentid+" #t8m_counter");
		
		counter.text(remaining);
	
		if (remaining <= 0) {
			var content=$("#status_textarea").val();
			if(content.length){
			    xajax_shortURL(content);
			}
			//counter.attr("class", "toomuch");
	    } else {
			//counter.attr("class", "");
		}
	
}
*/

var click_close=false;
var cur_dd_id;
function getSayText(texts,css){
	$("#qualifier_"+cur_dd_id+" #spansay").html(texts);
	$("#qualifier_"+cur_dd_id+" #spansay").attr("class", css);
	
	$("#qualifier_"+cur_dd_id+" #saytext").val(texts);
	$("#qualifier_"+cur_dd_id+" #sayclass").val(css);	
	
	$("#"+cur_dd_id).hide();
		
	click_close=false;
}

function display_dd(id){ 
	cur_dd_id = id;
	
	if(!click_close){
	  	var imgObj= document.getElementById("click_img_"+cur_dd_id);	 
	 
	  	var tmp=imgObj;
	  	var curTop=0;
	  	document.getElementById(id).style.display="block";
	 
	   	document.getElementById(id).style.left =imgObj.offsetLeft+"px";
	   	document.getElementById(id).style.top =imgObj.offsetTop+"px";
	   	click_close=true;
	}else{		
	  	click_close=false;
	}
	
}

function _display(id){
	var dobj = document.getElementById(id);		
	if(dobj.style.display=="none"){ 
		dobj.style.display="block";
	}
} 
		
function _hide(id){
	var dobj = document.getElementById(id);
	if(dobj.style.display=="block"){ 
		dobj.style.display="none";
	}
}
	
function insertSmile(id, key, area_name){	
	var content = $("#status_textarea_"+id+" #"+area_name).val();	
	if (content) content += " " + key;
	else content = key;
	
	$("#status_textarea_"+id+" #"+area_name).val(content);
	
	togleSmile(id);	  
}

function togleSmile(id){
	var curTop=0;
	var style_smile = document.getElementById("smiles_"+id).style;
	var togle_smile = document.getElementById("togle_smile_"+id);			
	var tmp=	togle_smile;	
	
	if(style_smile.display == "none"){				
		if(tmp.offsetParent) {
       		do {                           		
     			curTop += tmp.offsetTop;
   			} while(tmp = tmp.offsetParent)
        }
		document.getElementById("smiles_"+id).style.top=(togle_smile.offsetTop+20)+"px";
	    document.getElementById("smiles_"+id).style.left =(togle_smile.offsetLeft-30)+"px";		    
		style_smile.display = "block";
		document.getElementById("uparrow").style.display = "inline";
		document.getElementById("downarrow").style.display = "none";
	}
	else{
		style_smile.display = "none";
		document.getElementById("uparrow").style.display = "none";
		document.getElementById("downarrow").style.display = "inline";
	}
}

function getRandom(min, max)
{		
	var randomNum = Math.random() * (max-min); 

	// Round to the closest integer and return it
	return(Math.round(randomNum) + min); 
}
