var vAnimationInProgress=false;

/*Behind Google Search*/
	function WebSearch(){
			document.location = '/search.html?keywords='+$('#txt-search').attr('value');		
                }
	
	function Search404(){
                        document.location = '/search.html?keywords='+$('#404-search').attr('value');
                }



/*Behind Google Search*/
$(document).ready(function(){
	/*Behind Google Search*/
	$('#txt-search, #btn-search').keypress(function(e){
		if(e.which==13){ WebSearch();	}
	});
	$('#btn-search').click(function(){WebSearch();});



        $('#404-search, #404-btnsearch').keypress(function(e){
                if(e.which==13){ Search404();   }
        });
        $('#404-btnsearch').click(function(){Search404();});




	/*End Google Search*/
	$('ul>li:first-child,table>tbody>tr:first-child,table>tbody>tr>td:first-child').addClass('first-child');
	$('ul>li:last-child,table>tbody>tr:last-child,table>tbody>tr>td:last-child').addClass('last-child');
	
	$('label.overlabel').overlabel();
	$('img[src$=.png]').fixpng();
	$('.without-js').removeClass('without-js');

	/*Carrousel*/
	$('.our-customers>.carrousel').jCarouselLite({
		visible: 2,
		circular: true,
		scroll: 1,
		btnNext: '.out-customers-next',
		btnPrev: '.out-customers-prev',
		auto:000
	});
	
	//Finding and Hidden the Tab Content; except the first tab content 
	$('.tab-control').each(function(){
		//Hidden List Table
		$(this).find('.tab-content').not(':first-child').each(function(){
			$(this).css({display:'none'});
		});
		$('.tab-control ul.tab-titles li:hover').mouseover(function(){$(this).addClass('hover');}).mouseout(function(){$(this).removeClass('hover');});
		//Get First List Table ID
		var tmpID = $(this).find('.tab-titles li:first-child').addClass('tab-title-selected').find('a').attr('title');
		$(tmpID).addClass('tab-content-selected');
		$(this).find('ul.tab-titles>li>a').mouseover(function(){
			if(vAnimationInProgress==false){
				vAnimationInProgress=true;
				//Get List Table ID
				var tabContentID = $(this).attr('title');	
				$(this).parent().parent().find('li.tab-title-selected').removeClass('tab-title-selected');
				$(this).parent().addClass('tab-title-selected').parent().parent()
					.find('.tab-content-selected').removeClass('tab-content-selected')
					.hide();
				$(tabContentID).addClass('tab-content-selected')
					.show();//'1',function(){
						vAnimationInProgress=false;
					//});
			}
			return false;
		});
	});
	
	$('#mainTbl.home div.tab-control div.tab-contents').each(function(){
		$diference = $('#mainTbl.home div.col-left').height() - $('#mainTbl.home div.col-right').height();
		if($diference<0)
		{
			$height = $(this).height()-$diference;
			if( $.browser.msie && $.browser.version<7 )	{
				$(this).css('height',$height+'px');
			}else{
				$(this).css('min-height',$height+'px');
			}
		}else{
			$height=$('#mainTbl.home div.col-right>div:last-child>div.box-body').height()+$diference;
			if( $.browser.msie && $.browser.version<7 )	{
				$(this).css('height',$(this).height()+'px');
				$('#mainTbl.home div.col-right>div:last-child>div.box-body').css('height',$height+'px');
			}else{
				$(this).css('min-height',$(this).height()+'px');
				$('#mainTbl.home div.col-right>div:last-child>div.box-body').css('min-height',$height+'px');
			}
		}
	});
});

/* =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;
				}
			}
		});
	};
})(jQuery);
