var $location='http://'+document.domain + '/';
//var $location='http://'+document.domain + '/knowledge/';
$(function() {
	/*$('#subNav ul:gt(0)').hide();
			$('#topNav ul li a').mouseover(function(e){
						if(!$(this).is('.topNavActive')){
						var index=$('#topNav ul li a').index(this);
						$('#topNav ul li a').removeClass('topNavActive');
						$(this).addClass('topNavActive');
						$('#subNav ul:visible').hide();
						if($.browser.safari){
									$('#subNav ul:visible').hide();
									$('#subNav ul:eq('+index+')').fadeIn('slow');
						}else{
							$('#subNav').animate({'height':'0px'},200,function(){
								$(this).animate({'height':'40px'},200,function(){
									$('#subNav ul:visible').hide();
									$('#subNav ul:eq('+index+')').show();
								});
							});
						} // check safari
						} // if Active?
			});
	*/
	$('.switchContent').click(function(){
		var next=$(this).next();
		var prev=$(this).prev();
			if(next.is(':visible')){
				$(this).css({'background':'url('+$location+'images/thaiflag.gif) no-repeat top right'});
				next.slideUp('normal',function(){
						prev.slideDown('slow',function(){
							$(this).scrollTo(500,"linear");
							});
					});
			}else{
				$(this).css({'background':'url('+$location+'images/ukflag.gif) no-repeat top right'});
				prev.slideUp('normal',function(){
						next.slideDown('slow',function(){
							$(this).scrollTo(500,"linear");
							});
					});
			
			
			}

		
	}).next().hide();
	$('#footerR img').hoverEffect({over:1,out:.5,first:.5});
	$('.gototop').click(function(){
			$('body').scrollTo(500,"linear");
	});
}); // n doc

function preloadImages(){
	if(document.images){
		if(!document.imageArray) document.imageArray = new Array();
		var i,j = document.imageArray.length, args = preloadImages.arguments;
		for(i=0; i<args.length; i++){
			if (args[i].indexOf("#")!=0){
				document.imageArray[j] = new Image;document.imageArray[j++].src = args[i];
			}
		}
	}

} // n fnc

/**
		 / THIRD FUNCTION
		 * getPageSize() by quirksmode.com
		 *
		 * @return Array Return an array with page width, height and window width, height
		 */
		function ___getPageSize() {
			var xScroll, yScroll;
			if (window.innerHeight && window.scrollMaxY) {	
				xScroll = window.innerWidth + window.scrollMaxX;
				yScroll = window.innerHeight + window.scrollMaxY;
			} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
				xScroll = document.body.scrollWidth;
				yScroll = document.body.scrollHeight;
			} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
				xScroll = document.body.offsetWidth;
				yScroll = document.body.offsetHeight;
			}
			var windowWidth, windowHeight;
			if (self.innerHeight) {	// all except Explorer
				if(document.documentElement.clientWidth){
					windowWidth = document.documentElement.clientWidth; 
				} else {
					windowWidth = self.innerWidth;
				}
				windowHeight = self.innerHeight;
			} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
				windowWidth = document.documentElement.clientWidth;
				windowHeight = document.documentElement.clientHeight;
			} else if (document.body) { // other Explorers
				windowWidth = document.body.clientWidth;
				windowHeight = document.body.clientHeight;
			}	
			// for small pages with total height less then height of the viewport
			if(yScroll < windowHeight){
				pageHeight = windowHeight;
			} else { 
				pageHeight = yScroll;
			}
			// for small pages with total width less then width of the viewport
			if(xScroll < windowWidth){	
				pageWidth = xScroll;		
			} else {
				pageWidth = windowWidth;
			}
			arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
			return arrayPageSize;
		};
		
		function switchEOS(y){
			$('embed, object, select').css({ 'visibility' : ((y==1)?'hidden':'visible')});
		}
		
		function validFileUpload(id){
			$(id).change(function() {
						if ($(this).val()) { 
							var pattern = "jpe?g";
							var string=$(this).val().toLowerCase();
							if (string.match(new RegExp(".(" + pattern + ")$")) == null) {
								$(this).empty().val('');
								alert( 'Please choose .jpg file only'); return;
							} else { 
								//alert('valid'); 
							}
						}
				});
			
		} //

