/*Swift Javascript*/
$(document).ready(function(){
	$('label.overlabel').overlabel();
	$('img[@src$=.png]').fixpng();
	$('tr:first-child, td:first-child, ul:first-child, .section ul li p:first-child').addClass('first-child');
	$('tr:last-child, .section ul li p:last-child').addClass('last-child');
	$('div.box-degrade-blue, #lhn>li:first-child').box_round('only-top');
	$('#lhn>li:last-child').box_round('only-bottom');
	$('.section:even').addClass('clear');

	$(".f-copyright").each( function() {
	    var date = new Date();
	    var year = date.getFullYear();
	    
	    var inFooter = $(this).text().match(/\d{4}/g);	   
	    if(inFooter < year) {
	        $(this).text($(this).text().replace(inFooter, year));
	    }
	    
	});
	/*begin carousel*/
		try{
			 var listItems = $(".box-our-customers ul").children();
			 if(listItems.length>0){
				var mycarousel_itemList= new Array(listItems.length);
				for (i=0; i<listItems.length; i++)
				{
					var node = listItems[i];
					var anchorTag= $(node).children();
					var imageTag= $(node).children().children();
					var objItem = {
						href:$(anchorTag).attr('href'),
						url:$(imageTag).attr('src'),
						width:$(imageTag).width()
					};
					mycarousel_itemList[i]=objItem;
				}		
				function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt)
				{
					var idx = carousel.index(i, mycarousel_itemList.length);
					if(state=='next' || state=='init'){
						carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[idx - 1]));
						}
					if(state=='prev')
						{
						carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[idx - 1]));	
						}
				};
				
				function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt)
				{
					carousel.remove(i);
				};
				function mycarousel_getItemHTML(item)
				{
					return '<a target="_blank" href="'+item.href+'"><img   src="' + item.url + '" alt="" style="height:40px;" /></a>';
				};
				
				jQuery('.box-our-customers .ContentBlockCarousel>ul').jcarousel({
					wrap: 'circular',
					scroll:1,
					visible:4,
					itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback}/*,
					itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback}*/
				});
			 }
		}
		catch(ex){}
	/*end carousel*/
});

/* =jQuery Plugins*/
(function($){
	/* = plug-in : overlabel */
	$.fn.overlabel = function(options){
		var opts = $.extend( {},$.fn.overlabel.defaults, options );
		var selection = this.filter('label[for]').map(function(){
				var label = $(this);
				var id = label.attr('for');
				var field = $('#'+id);
				if(!field) return;
				var o = $.meta ? $.extend( {}, opts, label.data() ) : opts;
				label.addClass(o.label_class);
				var hide_label = function(){ label.css(o.hide_css) };
				var show_label = function(){ this.value || label.css(o.show_css) };
				$(field)
					.parent().addClass(o.wrapper_class).end()
					.focus(hide_label).blur(show_label).each(hide_label).each(show_label);
				return this;
		});
		return opts.filter ? selection : selection.end();
	};
	$.fn.overlabel.defaults = {
		label_class: 'overlabel-apply',
		wrapper_class: 'overlabel-wrapper',
		hide_css: { 'display': 'none' },
		show_css: { 'display': 'block' },
		filter: false
	};
	/* =plug-in : fix-png */
	$.fn.fixpng = function(){
		var hack = {
			isOldIE: $.browser.msie && $.browser.version < 7,
			filter: function(src){ return "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='scale',src='"+src+"');"; }
		};
		return this.each(function(){
			if(hack.isOldIE){
				var $$=$(this);
				if($$.attr('src')){
					var span = document.createElement('span');
					$(span).attr({
						id: $$.attr('id'), className: $$.attr('class')
					});
					$(span).css({
						display: 'inline-block', width: $$.width(), height: $$.height(), filter: hack.filter($$.attr('src')), float: $$.attr('align')=='left'?'left':($$.attr('align')=='right'?'right':'none')
					});
					this.outerHTML = span.outerHTML;
				}
			}
		});
	};
	/* = plug-in : box rounded */
	$.fn.box_round = function(options){
		var type=options?options:'default';/*default, only-top, only-bottom*/
		return this.each(function(){
			if(type=='default' || type=='only-top' ){
				var _tleft = document.createElement("span");_tleft.className="br-tleft";
				$(this).append(_tleft);
		  	}
			if(type=='default' || type=='only-top' ){
				var _tright= document.createElement("span");_tright.className="br-tright";
				$(this).append(_tright);
			}
			if(type=='default' || type=='only-bottom' ){
				var _bleft = document.createElement("span");_bleft.className="br-bleft";
				$(this).append(_bleft);
			}
			if(type=='default' || type=='only-bottom' ){
				var _bright = document.createElement("span");_bright.className="br-bright";
				$(this).append(_bright);
			}
		});
	};
})(jQuery);

function endKeyEvent(key_event,key,target){
   try{
      if(key_event==key){
         var _target=document.getElementById(target);
         _target.click();
         return false;
      }
   }catch(ex){
   }
}
function GoSearchInput(key,value) {
   if(key==13){
      GoSearch(value);
      return false;
   }
}
function GoSearch(theKeyword, evt) {
   if (theKeyword == "") {
       alert("Please enter a search term");
       //endBubble(evt)
      //Form1.theTerm.focus();
      return false;
   }else{
      window.document.location.replace("search.aspx?keyword=" + theKeyword);
      return false;
   }
}
function endBubble(evt){
   if(evt.cancelBubble == false){ 
      evt.cancelBubble = true; 
      evt.returnValue = false;
   }
   if (evt.stopPropagation) {
      evt.stopPropagation(); 
      evt.preventDefault();
   }
}