var wait;
var on = 0;

function clearMenu(){
	if(!on){
		$('#header dl ul').css({display:'none'});
		$('#iframe_shim').remove();
	}
	clearInterval(wait);
	wait = null;
}
function tabs(){
	$('.tabs a').click(function(){
        var id = this.hash.replace(/#/,'');
		$('.tabs a').removeClass('on');
		$('.group .section').each(function(){
			this.style.display = 'none';
		});
        $('#'+id)[0].style.display = 'block';
		$(this).addClass('on');
        return false;
    });
    $('.group .section').each(function(){
		this.style.display = 'none';
	});
    if($('#tab_s1')[0]) $('#tab_s1')[0].style.display = 'block';
}
// replace an object (id) with a flash movie
function flashmovie(mv,id,w,h){
	var so = new SWFObject(mv, "lakeview_mv", w, h, "6", "#fff");
	so.addParam("wmode", "transparent");
	so.write(id);
}

$().ready(function(){
	$('#header span').css({width: '169px',height: '21px',position: 'absolute',right: '20px',top: '47px'});

    // external urls
    $('a').click(function(){
	    if(this.href.match(/^http/i) && !this.href.match(location.host)){
		    window.open(this.href,'_');
		    return false;
	    }
	});
    // redirect to url from solution drop-down
    $('#solution').change(function(){
        var url = this.value.replace(/\s+/,'');
        if(url) location.href = url;
    });
	// sub-nav
	$('#header dl a').mouseover(function(){		
		on = 1;
		$(this).mouseout(function(){
			on = 0;
			wait = setInterval('clearMenu()',500);
		});

		var ul;
		var x = this.offsetLeft;
		var y = (this.offsetHeight -4) | 0;
		if(ul = $('ul',this.parentNode)[0]){
			$('#header dl ul').not(ul).css({display:'none'});
			$('#iframe_shim').remove();
			var _x = ul.style.left = x+'px';
			var _y = ul.style.top = y+'px';
			ul.style.zIndex = '100';

			if(ul.style.display!='block') ul.style.display = 'block';

			var w = (ul.offsetWidth)+'px';
			var h = ul.offsetHeight+'px';

			// iframe shim for msie
			if($.browser.msie){
				var iframe = '<iframe id="iframe_shim" src="javascript:false;" scrolling="no" frameborder="0" style="position:absolute; top:0px; left:0px;display:none;"></iframe>';
				$(this).after(iframe);
				$('#iframe_shim').css({width: w,height: h,left: _x,top: _y,display: 'block'});
			}
			$(ul).mouseout(function(){
				on = 0;
				wait = setInterval('clearMenu()',2000);
			});
			$('li,li a',ul).mouseover(function(){
				on = 1;
			});			
		}
	});
	
	// tabs
	if(location.href.match(/solutions\/manufacturing/)){
		tabs();
		$('#tab_overview a').addClass('on');
	}	
    
	// flash movie swaps
	/*
	var homepage = location.hostname+'\/?$';
	if(location.href.match(homepage)){
		flashmovie('/images/flash/software-and-services.swf','feature',568,205);
	}
	*/
	
	// hide default submit buttons
	if($('input.hidden-btn')[0]) $('input.hidden-btn').addClass('hide');
	
	// pagination
	// pagination
	if($('.pagination')[0]){
		$('.pagination #display,.pagination #pg').change(function(){
			var o = this;
			while(o.parentNode){
				o = o.parentNode;
				if(o.tagName.toLowerCase()=='form'){
					o.submit();
					break;
				}
			}
		});
	}

    // ie pngs
	/*@cc_on
	if(navigator.appVersion.match(/MSIE [0-6]\./)){
		$('img[@src*=".png"]').addClass('png');
		$('input[@src*=".png"]').addClass('png');
	}
	@*/
});