/*********************** Cookies Name ************************** 
Name:				Function:
------------------------------------
lingnanText 	= 	Font Size
lingnanCookie 	= 	Linear Version
***************************************************************/ 

var elems = null
var sizes = new Array()
var currSizes = new Array()

var defaultFontSize = 75;
if (navigator.appName == 'Microsoft Internet Explorer' && navigator.userAgent.match("MSIE 6.0")=="MSIE 6.0") { 
 defaultFontSize = 60; }
var currentFontSize = defaultFontSize;
$(document).ready(function(){		
						   

$('p[align=right]').css('text-align','right');
$('p[align=left]').css('text-align','right');
$('p[align=center]').css('text-align','center');
						   
						   
/******************** Block Element Style ***********************/  
$('div.block-style6').each(function () {
    $(this).find('div.block-text:last').css({
		"float" : "right",
		"margin-right" : "0"        
    });
});
/***************************************************************/  

						   

/*********************** Title Style ****************************/  
	$("div.block-style2 h3").each(function() {
	var me = $(this); //me.html( me.text().replace(/(^\w+)/,'<span>$1</span>') ); 
	me.html('<span>'+me.text()+'</span>') 
	});						   
	$("div.block-style3 h3").each(function() {
	var me = $(this); //me.html( me.text().replace(/(^\w+)/,'<span>$1</span>') ); 
	me.html('<span>'+me.text()+'</span>') 
	});						   
	$("div.block-style4 h3").each(function() {
	var me = $(this); //me.html( me.text().replace(/(^\w+)/,'<span>$1</span>') ); 
	me.html('<span>'+me.text()+'</span>') 
	});						   
	$("div.block-style6 h3").each(function() {
	var me = $(this); //me.html( me.text().replace(/(^\w+)/,'<span>$1</span>') ); 
	me.html('<span>'+me.text()+'</span>') 
	});						   
/***************************************************************/  	
	
	

/*********************** Quick Link Menu  **********************/
    linkEm = $(".quick-links em")
    quickLinks = $(".quick-links .items")
    
    var timer = null

    if (Get_Cookie('lingnanCookie')=="Standard" || Get_Cookie('lingnanCookie')==null){

    $(linkEm).click(function(){
        $(quickLinks).toggle("def")
        if($(linkEm).parent().hasClass("arrow")) {
            $(linkEm).parent().removeClass("arrow")
            clearTimeout(timer)
        } else {
            $(linkEm).parent().addClass("arrow")
            timer = setTimeout(function(){
                $(quickLinks).hide("def")
                $(".quick-links").removeClass("arrow")
            }, 4000)
        }
    })
    
    $(linkEm).mouseover(function(){
        clearTimeout(timer)
    })
    
    $(quickLinks).mouseover(function(){
        clearTimeout(timer)
    }).mouseout(function(){
        timer = setTimeout(function(){
            $(quickLinks).hide("def")
            $(".quick-links").removeClass("arrow")
        }, 3000)
    })
	
	}
/***************************************************************/   
   

	
/************************* Main Menu ***************************/
    elems = $("#main-col *, #right-side *, #center-col *, #right-col *")     
    links_elm = $("#navigation a")	

	links_elm.mouseover(function(){
        $('> span', this).toggleClass("bottom_border_display")
    }).mouseout(function(){
		$('> span', this).toggleClass("bottom_border_display")
	})		

	html_val = new Array()
    
    jQuery.each(links_elm, function(i, val){
        html_val[i] = $(this).html()
        $(this).html(html_val[i]+"<span class='bottom_border'></span>")
	$("#navigation a.active .bottom_border").css("display","block")
	/*if(i==(links_elm.length-1)) {
            $(this).parent().addClass("last")
        }*/
    })
/***************************************************************/



/******************** Text Size Cookie *************************/
	if (Get_Cookie('lingnanText')){
		setFontSize(Get_Cookie('lingnanText'));
	}	
	else{
		setFontSize(75);
	}
/***************************************************************/



/************************ Tsz King *****************************/
	$("#decreaseFont").click(function() {
		changeFontSize(-1);
		
	});
	$("#defaultFont").click(function() {
		revertStyles();
	});
	$("#increaseFont").click(function() {
		changeFontSize(1);
	});
/***************************************************************/	
})


/*********************** Change font-size **********************/


function revertStyles(){
	currentFontSize = defaultFontSize;
	changeFontSize(0);
	Delete_Cookie( 'lingnanText', '/', location.host );
}

function changeFontSize(sizeDifference){
	currentFontSize = parseInt(currentFontSize) + parseInt(sizeDifference * 10);
	if(currentFontSize > 95){
		currentFontSize = 95;
	}else if(currentFontSize < 60){
		currentFontSize = 60;
	}
	createCookie('lingnanText',currentFontSize);
	setFontSize(currentFontSize);
};
/***************************************************************/



/********************** Linear Version **************************/
function setFontSize(fontSize){
	var stObj = (document.getElementById) ? document.getElementById('content_area') : document.all('content_area');

     if (Get_Cookie('lingnanCookie')=="Standard" || Get_Cookie('lingnanCookie')==null){
            	document.body.style.fontSize = fontSize + '%';
	} else {
                document.body.style.fontSize = '130%';
	}
};
/***************************************************************/



/********************* Cookie Settings *************************/
function createCookie(name,value,days) {
 if (days != null) {
 var date = new Date();
 date.setTime(date.getTime()+(days*24*60*60*1000));
 var expires = "; expires="+date.toGMTString();
 }
 else expires = "";
 document.cookie = name+"="+value+expires+"; path=/";
}

function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}

		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found ) 
	{
		return null;
	}
}
/***************************************************************/


