function openLightbox(_url, _width, _height) {
    if(_width==undefined) { _width=300; }
    if(_height==undefined){ _height=250; }
    var anchor = $('a#custom-open-lightbox');
    if( $('a#custom-open-lightbox').length==0 ) {
        anchor = $('<a id="custom-open-lightbox" class="hid" onclick="return false;"></a>');
        $('body').prepend(anchor);
        anchor.click(function(){
            var _this = $(this);
            var href = _this.attr('title');
            var _w = parseInt(_this.attr('lightbox_width'));
            var _h = parseInt(_this.attr('lightbox_height'));
            var _left = _w/2;
            $('body').prepend("<div class='pagelayer'><div class='internalPopupShadow'></div><div class='internalPopupDiv internalPopupDivCenter' style='margin-left:-"+_left.toString()+"px !important;'><a class='btn-close' href='#' onclick='return tb_remove();'><img border='0' src='/uploadedImages/close.gif' alt='Close this window' title='Close this window'/></a><iframe scrolling='no' frameBorder='0' src='"+href+"' style='width:"+_w.toString()+"px; height:"+_h.toString()+"px; '></iframe></div></div>");
            var _reset = $.browser.msie ? "1%" : "auto";
            $('.internalPopupShadow').css("height", _reset);
            var _heightbody = $('body').outerHeight(true);
            $('.internalPopupShadow').css("height", _heightbody+353);
            var isOldIE = $.browser.msie && $.browser.version < 7;
            if( isOldIE ){
                $(window).scroll(function(args){
                    var _top = $(document).scrollTop();
                    $('.internalPopupDiv').css("margin-top", _top+"px");
                });
            }
            return false;
        });
    }
    anchor.attr('lightbox_width',_width);
    anchor.attr('lightbox_height',_height);
    anchor.attr('title',_url);
    anchor.trigger('click');
}
$(document).ready(function(){

    /*only for teset*/
    if( document.location.href.toString().indexOf('js-debug=true')!=-1 )
    {
        openLightbox("http://www.google.com");
    }

	$('#exitBox').exitBox({
		cookieName: 'ADT_Exit_Message',
		cookieDuration: 2
	})
	
	$('div.jtab-control').each(function(){
        var _jcontrol = $(this);
        var _jcontent = $('.jtab-content>.jtab-content-box',_jcontrol);
        _jcontrol.attr('actioninprogress','false');
        _jcontrol.find('>ul.jtab-items>li>a').click(function()
        {
            if( _jcontrol.attr('actionInProgress')!='true' )
            {
                _jcontrol.attr('actioninprogress','true');
                var _this = $(this);
                var _target = _this.attr('href');
                _jcontrol.find('>ul.jtab-items>li').removeClass('jtab-items-selected');
                _this.parent().addClass('jtab-items-selected');
                //_jcontent.filter('.jtab-content-box-selected').removeClass('jtab-content-box-selected');
                _jcontent.filter('.jtab-content-box-selected').fadeOut(function()
                {
                    _jcontent.filter('.jtab-content-box-selected').removeClass('jtab-content-box-selected');
                    $(_target, _jcontrol).fadeIn(function()
                    {
                        $(_target, _jcontrol).addClass('jtab-content-box-selected');
                        _jcontrol.attr('actioninprogress','false');
                    });
                });
                //$(_target, _jcontrol).addClass('jtab-content-box-selected');
            }
            return false;
        });
    });
    
	$('label.overlabel').overlabel();
	$('img[src$=.png]').fixpng();
	$('div.three-cols div.col1, div.three-cols div.col2, div.three-cols div.col3').equalizeCols();
	$('.eq').equalizeCols();
	$('.four-cols a.box .image').equalizeCols();
	$('div:last-child, li:last-child, td:last-child , a:last-child, tr:last-child, th:last-child  ').addClass("last-child");
	$('div:first-child,li:first-child, td:first-child, a:first-child, tr:first-child, th:first-child ').addClass("first-child");

	$('.open-light-box, .open-light-box-toLeft, .open-light-box-toTopMenu').click(function(){
	    var _this = $(this);
        var href = _this.attr('title');
        var cssAlign = '';
        try{
            if( _this.hasClass('open-light-box-toLeft') ) {
                cssAlign = ' internalPopupDivLeft ';
            }
            else if( _this.hasClass('open-light-box-toTopMenu')){
                cssAlign = ' internalPopupDivTopMenu ';
            }
            else if( _this.parents('div.left-content').length>0 || _this.parents('div.three-cols').length>0 ){
                cssAlign = ' internalPopupDivCenter ';
            }
        }catch(ex){}
        $('body').prepend("<div class='pagelayer'><div class='internalPopupShadow'></div><div class='internalPopupDiv"+cssAlign+"'><a class='btn-close' href='#' onclick='return tb_remove();'><img border='0' src='/uploadedImages/close.gif' alt='Close this window' title='Close this window'/></a><iframe scrolling='no' frameBorder='0' src='"+href+"' style='width:300px; height:250px; '></iframe></div></div>");
        var _reset = $.browser.msie ? "1%" : "auto";
        $('.internalPopupShadow').css("height", _reset);
        var _heightbody = $('body').outerHeight(true);
        $('.internalPopupShadow').css("height", _heightbody+353);
        var isOldIE = $.browser.msie && $.browser.version < 7;
        if( isOldIE ){
            $(window).scroll(function(args){
                var _top = $(document).scrollTop();
                $('.internalPopupDiv').css("margin-top", _top+"px");
            });
        }
        return false;
    });

	/* search input*/ 
	$("#txt-search").keydown( function(event) {
		if(event.keyCode == 13) {
 		
		event.preventDefault();
	 	event.stopPropagation();
		$("form").submit(function(event) {
			event.preventDefault();
		 	event.stopPropagation();
			return false;
		});
		RedirectUser();
		return false;
	 	}
	 });
	$("#btnSearch").click(function(){ RedirectUser(); });
	
   var _main = $('div#aniBanners');
   if(_main.length>0)
   {
		_main.append('<span class="btn-previous"></span><span class="btn-next"></span>');
      var _buttons = $('ul.buttons>li>a', _main);
      _main.data('_previous', null);
      _buttons.click(function(){
         var _this = $(this);
         var _href = _this.attr('href');
         var _previous = _main.data('_previous');
         var _current = $('ul.img-banners>li:visible', _main);
         $('ul.img-banners>li', _main).not(':visible').css('opacity','0');
         var _next = $(_href, _main);
         if( _current.attr('id')!=_next.attr('id') )
         {
            if(_previous!=null){
	            _previous.css({'z-index':'100'}).stop();
	            _current.css({'z-index':'100'}).stop();
            }
				$('ul.buttons>li', _main).removeClass('selected');
				_this.parent().addClass('selected');
            _current.animate( {opacity:0, 'z-index':'100' }, {duration:1000, queue:false} );
            _next.css('display','block').animate( {opacity:1, 'z-index':'200' }, 1000, function() { /*_main.data('inprogress', 'false');*/ _current.css('display','none'); _next.css('display','block'); } );
            //_current.css({display:'block', 'z-index':'100'}); 
            //_next.css({display:'block', left:615, 'z-index':'200'});
            //_next.animate( {left:0}, 200, function() { _current.css('display','none'); } );
            _main.data('_previous', _current);
         }
         return false;
      });
		var _ctemp = $('ul.img-banners>li:visible', _main);
		var _cid = _ctemp.attr('id');
		$('ul.buttons>li>a[href=#'+_cid+']', _main).parent().addClass('selected');
		var _citem = null;
		$('span.btn-next', _main).click(function(){
			if( _citem==null )
			{
				var _current = $('ul.img-banners>li:visible', _main);
				var _id = _current.attr('id');
				var _button = $('ul.buttons>li>a[href=#'+_id+']', _main);
				_citem = _button.parent().next();
			}else{
				if( _citem.is(':last-child') )
				{
					_citem = _citem.parent().find('>li:first-child');
				}else{
					_citem = _citem.next();
				}
			}
			_citem.find('>a').trigger('click');
		});
		$('span.btn-previous', _main).click(function(){
			if( _citem==null )
			{
				var _current = $('ul.img-banners>li:visible', _main);
				var _id = _current.attr('id');
				var _button = $('ul.buttons>li>a[href=#'+_id+']', _main);
				_citem = _button.parent().parent().find('>li:last-child');
			}else{
				if( _citem.is(':first-child') )
				{
					_citem = _citem.parent().find('>li:last-child');
				}else{
					_citem = _citem.prev();
				}
			}
			_citem.find('>a').trigger('click');
		});
   }
});

function tb_remove(){
	 $('.pagelayer').remove();
	 return false;
}

/* =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;
				}
			}
		});
	};
	
	$.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 = "corner tl";
		$(this).prepend(_tleft);
		}
		if (type == 'default' || type == 'only-top') {
		var _tright = document.createElement("span"); _tright.className = "corner tr";
		$(this).prepend(_tright);
		}
		if (type == 'default' || type == 'only-bottom') {
		var _bleft = document.createElement("span"); _bleft.className = "corner bl";
		$(this).prepend(_bleft);
		}
		if (type == 'default' || type == 'only-bottom') {
		var _bright = document.createElement("span"); _bright.className = "corner br";
		$(this).prepend(_bright);
		}
		if (type == 'title' || type == 'title-left') {
		var _bleft = document.createElement("span"); _bleft.className = "left-title";
		$(this).prepend(_bleft);
		}
		if (type == 'title' || type == 'title-right') {
		var _bright = document.createElement("span"); _bright.className = "right-title";$(this).prepend(_bright);}});
	};

	/* =plug-in : equal-heights */
	$.fn.equalizeCols = function(){
		var height = 0,
			 reset = $.browser.msie ? "1%" : "auto";
		return this
			.css("height", reset)
			.each(function() {
				height = Math.max(height, $(this).outerHeight(true));
			})
			.css("height", height)
			.each(function() {
				var h = $(this).outerHeight(true);
				if (h > height) {
					$(this).css("height", height - (h - height));
				};
			});
	};
})(jQuery);

function RedirectUser()
{
    if($('#txt-search').val() != '')
	{
	    var searchUrl = '/Search.aspx?q=' + $('#txt-search').val();
		window.location.href = searchUrl;
    }
}
