ROTATE = 0;
var TABS;
var OVER = false;
var TIMER;
var PTIMER;
var POPUPTIMEOUT = 1000;
function checkNextSlide(event, tabIndex){
	
	//alert(TABS.getIndex());
	if(OVER){
		TABS.pause();
		return;
	}
	ROTATE++;
	var n = $(".tabs a").length;
	if(ROTATE >= n && TABS.getIndex() == n-1){		
	TABS.stop();		
	}
}
$(document).ready(function(){
	
	var ie6 = false;
	var ie7 = false;
	
	if ($.browser.msie && $.browser.version.substr(0,1)<7) {
		ie6 = true;
	}else if($.browser.msie && $.browser.version.substr(0,1)>=7){
		ie7 = true;
	}
	
	try{
		MEDIA_PLAYER = $('#media-overlay').overlay({api:true, expose:{color:"#000000", zIndex:2147483635}});
		$('#media-overlay').hide();
		
		MEDIA_PLAYER.onBeforeLoad(function(){
			$('#flashmedia > embed').css('zIndex', 2147483644);
		});
		
	}catch(err){}
	
	if($('body').attr('id') == 'slideshow'){
		var tabparams = {current: 'hover',effect: 'fade',fadeOutSpeed: "slow", event:'click', rotate: true};
		var slideparams = {autoplay:false, autopause:false,interval:6000,clickable: false, onBeforeNext:checkNextSlide};
//		alert($(".tabs").length);
		var tb = $('.tabs');
//		alert($(tb).tabs);
		TABS = $(".tabs").tabs(".home_content1 > div ", tabparams);
		var slides = TABS.slideshow(slideparams);
		var n = $(".tabs a").length;
		$("#nextbutton").click(function(){TABS.next()});
		$("#threeI a").click ( function() {
											clearTimeout(TIMER);
								OVER = true;
											}, function(){ if(ROTATE < n-1) { TIMER = setTimeout(TABS.play, 6000);}OVER = false;});		
			
		TABS = $(".tabs").tabs();
		TIMER = setTimeout(TABS.play,6000);
	}

	$("#threeI a").hover( function() {
//		alert("test");
		$("#threeI a").removeClass('over');
		$(this).addClass('over');
		$("#threeIPopupLoader").fadeIn();
		var toLoad = $(this).next().clone();
		$("#threeIPopupInner").empty();
		$("#threeIPopupInner").append(toLoad);
	}, function () {
		$("#threeI a").removeClass('over');
		$("#threeIPopupLoader").hide();
	})	
	
	$("#btmtab a").hover( function() {
		$("#btmtab a").removeClass('over');
		$(this).addClass('over');
		$("#threeIPopupLoader").fadeIn();
		var toLoad = $(this).next().clone();
		$("#threeIPopupInner").empty();
		$("#threeIPopupInner").append(toLoad);
	}, function () {
		$("#threeI a").removeClass('over');
		$("#threeIPopupLoader").hide();
	})

	$("#btmtab2 a").hover( function() {
		$("#btmtab2 a").removeClass('over');
		$(this).addClass('over');
		$("#threeIPopupLoader").fadeIn();
		var toLoad = $(this).next().clone();
		$("#threeIPopupInner").empty();
		$("#threeIPopupInner").append(toLoad);
	}, function () {
		$("#threeI a").removeClass('over');
		$("#threeIPopupLoader").hide();
	})

	$("#subnav #assetviewer li").hover( function() {
		var x = $(this).position();
		var y = $(this).offset();
		if(ie6){ x = x.left + 169; } else { x = x.left + 173; }
		if(ie6){ y = y.top - 450; } else { y = y.top - 250; }
		x = x.toString();	x = x + "px";
		y = y.toString();	y = y + "px";
		$("#subnav #assetviewer li").removeClass('over');
		$(this).addClass('over');
		$("#subnavPopupLoader").css('left',x);
		$("#subnavPopupLoader").css('top',y);
		$("#subnavPopupLoader").fadeIn();
		var toLoad = $(this).find('.subnavPopup').clone();
		$("#subnavPopupInner").empty();
		$("#subnavPopupInner").append(toLoad);
	}, function () {
    })

	$("#subnavPopupClose").click(closePopupNow);
	$("#subnavPopupLoader").hover(function(){clearTimeout(PTIMER)}, closePopup);
	$("#assetviewer li").hover(function(){clearTimeout(PTIMER)}, closePopup);
	$('#contentInner, #footer').click(closePopupNow);
	$("#tabs li").hover( function() {
		//$("#tabs li").removeClass('active');
		var theClass = $(this).attr('class');
//		alert(theClass);
		if(theClass!="active"){
			$(this).addClass('hover');
		}
	}, function () {
		$(this).removeClass('hover');
    })	
	
	$("#tabs li").click( function() {
		$(this).removeClass('hover');
		$("#tabs li").removeClass('active');
		$(this).addClass('active');
		var toShow = "#" + $(this).children().eq(0).attr('class');
		$("#contentInner > div").fadeOut();
		$(toShow).fadeIn();
	}, function () {
		$(this).removeClass('active');
    })		
	
	$(".subNavLinks li").hover( function() {
		$(this).addClass('hover');
	}, function () {
		$(this).removeClass('hover');
    })	
	$(".subNavLinks li[id!=current]").hover( function() {
		$(this).attr('id','current');
	}, function () {
		$(this).attr('id','');
	})
/*	$(".subNavLinks li[id==current]").click( function() {
		$(this).next().fadeOut();
	}, function () {
	})	*/

	$(".coreattribute-img").hover( function() {
		var x = $(this).position();
		if(ie6){ x = x.left + 221; } else if(ie7){ x = x.left + 221; } else { x = x.left + 221; }
		x = x.toString();	x = x + "px";
		$("#coreattributes div").removeClass('over');
		$(this).addClass('over');
		$("#subnavPopupLoader").css('left',x);
		$("#subnavPopupLoader").fadeIn();
		var nextID = "#"+$(this).attr('id')
		var toLoad = $(nextID).next().clone();
		if(nextID == '#coreattributes5'){
			//$("#subnavPopupLoader").css('height',446);
		} else if(nextID == '#coreattributes4'){
			//$("#subnavPopupLoader").css('height',350);						
		} else {
			//$("#subnavPopupLoader").css('height',330);			
		}
        $("#subnavPopupInner").empty();
		$("#subnavPopupInner").append(toLoad);
	}, function () {
    })

//$('#menuh').load('/top_nav.html', onReady); 
	
	onReady();

});

function onReady(){

	var ie6 = false;
	var ie7 = false;
	
	if ($.browser.msie && $.browser.version.substr(0,1)<7) {
		ie6 = true;
	}else if($.browser.msie && $.browser.version.substr(0,1)>=7){
		ie7 = true;
	}

	$(".menuh_tab").hover( function() {
		$(".menuh_tab_active").attr('class','menuh_tab');
		$(this).attr('class','menuh_tab_active');
		$("#subnav a").removeClass('over');
		$("#coreattributes div").removeClass('over');
		$("#subnavPopupLoader").fadeOut();
	}, function () {
    })	
	$("#menuh ul").hover( function() {
	}, function () {
		$(".menuh_tab_active").attr('class','menuh_tab');
    })	
	if(ie6){
		$("#menuh > ul").hover( function() {
			//$(this).parent().css('height',100+"px");
		}, function () {
			//$(this).parent().css('height','auto');
		})	
	}


	parseStylesheets()
}

function menuHandler(responseText, textStatus, XMLHttpRequest){
	 if(REQ.readyState == 4)
    {
        // and the file actually exists
        if(REQ.status == 200)
        {
            // say it exists and show the image
          alert('exists');
        }
        else
        {
            // say it doesn't exist and hide the image
           alert('no exist');
        }
    }

}

function closeFlash() {
    MEDIA_PLAYER.close();
}
function registerClicker(){	
	$('#flashmedia').click(function(){MEDIA_PLAYER.close();});
	}
function showMedia(src, title){

	$('#flashmedia').flashembed({src:'../swf/mediaplayer.swf', allowscriptaccess:'always', wmode:'transparent', w3c:false, cacheBusting:true}, {src:src, mediaTitle:title});
	MEDIA_PLAYER.load();
}

function goImgWin(Wtitle,myImage,myWidth,myHeight,origLeft,origTop) {

//alert(myImage);

myHeight += 24;
myWidth += 24;
TheImgWin = window.open('','image','height=' +
myHeight + ',width=' + myWidth +',toolbar=no,directories=no,status=yes,' +'menubar=no,scrollbars=no,resizable=no');

// Write the contain of window
TheImgWin.document.write("<html><head><title>"+Wtitle+"</title>");
TheImgWin.document.write("</head><body leftmargin='0' rightmargin='0' topmargin='0' bottommargin='0'>");
TheImgWin.document.write("<img src="+myImage+" border=0 >");
TheImgWin.document.write("</body></html>");
TheImgWin.resizeTo(myWidth+2,myHeight+30);
/*TheImgWin.moveTo(origLeft,origTop);*/
TheImgWin.focus();
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
var csshoverReg = /(^|\s)((([^a]([^ ]+)?)|(a([^#.][^ ]+)+)):(hover|active))|((a|input|textarea)([#.][^ ]+)?:unknown)/i,
currentSheet, doc = window.document, hoverEvents = [], activators = {
	onhover:{on:'onmouseover', off:'onmouseout'},
	onactive:{on:'onmousedown', off:'onmouseup'},
	onunknown:{on:'onfocus', off:'onblur'}
}

function parseStylesheets() {
	if(!/MSIE (5|6)/.test(navigator.userAgent)) return;
	window.attachEvent('onunload', unhookHoverEvents);
	var sheets = doc.styleSheets, l = sheets.length;
	for(var i=0; i<l; i++) 
		parseStylesheet(sheets[i]);
}
	function parseStylesheet(sheet) {
		if(sheet.imports) {
			try {
				var imports = sheet.imports, l = imports.length;
				for(var i=0; i<l; i++) parseStylesheet(sheet.imports[i]);
			} catch(securityException){}
		}

		try {
			var rules = (currentSheet = sheet).rules, l = rules.length;
			for(var j=0; j<l; j++) parseCSSRule(rules[j]);
		} catch(securityException){}
	}

	function parseCSSRule(rule) {
		var select = rule.selectorText, style = rule.style.cssText;
		if(!csshoverReg.test(select) || !style) return;
		
		var pseudo = select.replace(/[^:]+:([a-z-]+).*/i, 'on$1');
		var newSelect = select.replace(/(\.([a-z0-9_-]+):[a-z]+)|(:[a-z]+)/gi, '.$2' + pseudo);
		var className = (/\.([a-z0-9_-]*on(hover|active|unknown))/i).exec(newSelect)[1];
		var affected = select.replace(/:(hover|active|unknown).*$/, '');
		var elements = getElementsBySelect(affected);
		if(elements.length == 0) return;

		currentSheet.addRule(newSelect, style);
		for(var i=0; i<elements.length; i++)
			new HoverElement(elements[i], className, activators[pseudo]);
	}

function HoverElement(node, className, events) {
	if(!node.hovers) node.hovers = {};
	if(node.hovers[className]) return;
	node.hovers[className] = true;
	hookHoverEvent(node, events.on, function() { node.className += ' ' + className; });
	hookHoverEvent(node, events.off, function() { node.className = node.className.replace(new RegExp('\\s+'+className, 'g'),''); });
}
	function hookHoverEvent(node, type, handler) {
		node.attachEvent(type, handler);
		hoverEvents[hoverEvents.length] = { 
			node:node, type:type, handler:handler 
		};
	}

	function unhookHoverEvents() {
		for(var e,i=0; i<hoverEvents.length; i++) {
			e = hoverEvents[i]; 
			e.node.detachEvent(e.type, e.handler);
		}
	}

function getElementsBySelect(rule) {
	var parts, nodes = [doc];
	parts = rule.split(' ');
	for(var i=0; i<parts.length; i++) {
		nodes = getSelectedNodes(parts[i], nodes);
	}	return nodes;
}
	function getSelectedNodes(select, elements) {
		var result, node, nodes = [];
		var identify = (/\#([a-z0-9_-]+)/i).exec(select);
		if(identify) {
			var element = doc.getElementById(identify[1]);
			return element? [element]:nodes;
		}
		
		var classname = (/\.([a-z0-9_-]+)/i).exec(select);
		var tagName = select.replace(/(\.|\#|\:)[a-z0-9_-]+/i, '');
		var classReg = classname? new RegExp('\\b' + classname[1] + '\\b'):false;
		for(var i=0; i<elements.length; i++) {
			result = tagName? elements[i].all.tags(tagName):elements[i].all; 
			for(var j=0; j<result.length; j++) {
				node = result[j];
				if(classReg && !classReg.test(node.className)) continue;
				nodes[nodes.length] = node;
			}
		}	
		
		return nodes;
	}
function closePopup(){
			PTIMER = setTimeout(function(){
			$('.coreattribute-img').removeClass('over');
			$("#subnav #assetviewer li").removeClass('over');
			$("#subnavPopupLoader").fadeOut();
										  }, POPUPTIMEOUT)
	}
	function closePopupNow(){
			clearTimeout(PTIMER)
$('.coreattribute-img').removeClass('over');
			$("#subnav #assetviewer li").removeClass('over');
			$("#subnavPopupLoader").fadeOut();
										 
	}
	
function avi(){
		window.open('/avi/OSP_April08.html','window','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=345,height=400');
}
	