$(document).ready(function(){
	makeLangSelectorHover();
	makeSearchHintable();
	autoLogoWidth();
	hideEmptyInfo();
	//adjustBannerPosition();
	avoidBannerContext();
	hoverPartners();
	hookGooglemapThumbClick();
	
	initFreezeScreen();

	fixBreadcrumbInfo();
});

function makeLangSelectorHover()
{
	$('#langSelector').hover(
		function()
		{
			$(this).find('ul').show();
		},
		function()
		{
			$(this).find('ul').hide();
		}
	);
}

function makeSearchHintable()
{
	var $input=$('#header form .text');
	var $submit=$('#header form .submit');
	
	var searchIsEmpty=true;
	var strSearch=$submit.attr('value');
	var autoColor='#999999';
	var userColor='black';
	
	$input.focus(function(){
		if (searchIsEmpty)
		{
			$(this).attr('value','');
			$(this).css('color',userColor);
		}
	});

	$input.blur(function(){
		if ($(this).attr('value')=='')
		{
			searchIsEmpty=true;
			$(this).attr('value',strSearch);
			$(this).css('color',autoColor);
		}
		else
		{
			searchIsEmpty=false;
		}
	});
		
	$input.attr('value',strSearch);
	$input.css('color',autoColor);
}

function autoLogoWidth()
{
	$(window).resize(function(){
		$('#logo').width(
			$(window).width()<$('#container').width() ?
			$('#container').width() :
			$(window).width()
		);
		
		$logo_click= $('#logo_click');
		$logo_click.css('left',($('#container').offset().left+770) + 'px');
		$logo_click.css('top','25px');

	});
	
	$(window).resize();
}

function hideEmptyInfo()
{
	$('#left p.info').parent().hide();
}

function hoverPartners()
{
	$('#footer .partners a').hover(
		function()
		{
			$this=$(this);
			css=$this.css('background-image');
			css=css.replace('.png','_hover.png');

			$this.css('background-image',css);
		},
		function()
		{
			$this=$(this);
			css=$this.css('background-image');
			css=css.replace('_hover.png','.png');

			$this.css('background-image',css);
		}
	);
}

/*
function adjustBannerPosition()
{
	$('#banner').prependTo($('#container_inside'));
}
*/

function avoidBannerContext()
{
	var bannerContainer=document.getElementById('slide_container');
	if(bannerContainer!=null)
	{
		bannerContainer.oncontextmenu=function(){return false;};
	}
}

function initFreezeScreen() {
    //show free screen
    var freeze=$('#freezeScreen');
    freeze.css('background-color','black');
    freeze.css('filter','alpha(opacity=80)');
    freeze.css('opacity','0.8');
    freeze.css('position','absolute');
    freeze.css('left','0');
    freeze.css('top','0');
    freeze.css('width','100%');
    freeze.css('height',$(document).height() + 'px');
    freeze.css('z-index',999);
    freeze.css('display','none');

    var pop=$('#popup');
    //pop.css('position','absolute');

    freeze.click(function() {
        $(this).hide();
        pop.empty();
		
		$(this).next().remove();
    })
}

function hookGooglemapThumbClick(src,freezeLayer)
{
	//src: a jquery selector to find the anchor that contains a thumnbnail map image
	//freezeLayer: a jquery selector to find a black transparent background
	if(typeof(src)=='undefined' || src=='') src='#main a.mapthumb';
	if(typeof(freezeLayer)=='undefined' || freezeLayer=='') freezeLayer='#freezeScreen';

	$mapthumbs=$(src);
	$mapthumbs.click(function(){
		$maplayer=$('#' + $(this).attr('rel'));
		if($maplayer.length>0)
		{
			$maplayer=$maplayer.clone().attr('id','');
			$maplayer
				.css('display','block')
				.css('margin','0 auto')
				.css('display','block')
				.css('z-index','9999')
				.css('position','absolute')
				.insertAfter($('#freezeScreen'))
				;
			
			$maplayer
				.css('top',( $(window).height() - $maplayer.height() ) / 2 + $(window).scrollTop() + 'px')
				.css('left',( $(window).width() - $maplayer.width() ) / 2 + $(window).scrollLeft() + 'px')
			;
			
			$(freezeLayer).show().css('height',$(document).height() + 'px');
		
			return false;
			
		}
	});
}

function fixBreadcrumbInfo()
{
	$span=$('.mod_breadcrumb span');
	if ($span.text()=='Jobs Detail')
	{
		$span.text($('#main h2:eq(0)').text());
	}
	else if ($span.text()=='News Detail')
	{
		$span.text($('#main h2:eq(0)').text());
	}
}




window.onload=function()
{
	$('.loading').css('background-image','none');
}

