var onParent;
var onChild;
var timer;
var currentChild;

var pink = '#f692b4';
var notQuiteBlack = '#333333';

function initParentChild(parent, child) {
	parent.addEvent('mouseenter', function(event) {
		
		$clear(timer);

		if (currentChild != null) {
			currentChild.setStyle('display', 'none');
		}
		
		currentChild = child;
		currentChild.setStyle('display', 'block');
		
		if (onParent != null && parent != onParent) {
		    onParent.setStyle('color', notQuiteBlack);
		    if (onChild != null) {
		    	onChild.setStyle('display', 'none');
		    }
		}
    });

    parent.addEvent('mouseleave', function(event) {
    	
    	$clear(timer);
    	timer = (function(event) {
    		child.setStyle('display', 'none');
    		setOn();
    	}).delay(500);
    });
    
    child.addEvent('mouseenter', function(event) {
    	$clear(timer);
    });

    child.addEvent('mouseleave', function(event) {
    	$clear(timer);
    	timer = (function(event) {
    		child.setStyle('display', 'none');
    		setOn();
    	}).delay(500);
    });
}

function setOn() {
	if (onParent != null) {
	    onParent.setStyle('color', pink);
	    if (onChild != null) {
	    	onChild.setStyle('display', 'block');
	    }
	}
}

function subscribe_nav() {
		
	var currentPage = location.href;
	
	if (currentPage.test(/style_guide.jsp/)) {
		onParent = $('styleGuide');
		onChild = $('styleGuideDropdown');
	} else if (currentPage.test(/style_guide\/bra_fit_guide.jsp/)) {
		
		onParent = $('styleGuide');
		onChild = $('styleGuideDropdown');
		$('sgdsBras').setStyle('color', pink);
		
	} else if (currentPage.test(/style_guide\/lounge_editorial.jsp/)) {
		
		onParent = $('styleGuide');
		onChild = $('styleGuideDropdown');
		$('sgdsLoungeLooks').setStyle('color', pink);
		
	} else if (currentPage.test(/style_guide\/lounge_quiz.jsp/)) {
		
		onParent = $('styleGuide');
		onChild = $('styleGuideDropdown');
		$('sgdsLoungeQuiz').setStyle('color', pink);
		
	} else if (currentPage.test(/style_guide\/fragrance.jsp/)) {
		
		onParent = $('styleGuide');
		onChild = $('styleGuideDropdown');	
		
	} else if (currentPage.test(/style_guide\/nfl_collection.jsp/)) {
		
		onParent = $('styleGuide');
		onChild = $('styleGuideDropdown');
		$('sgdsNFL').setStyle('color', pink);	
		
	} else if (currentPage.test(/style_guide\/looks_we_love.jsp/)) {
		
		onParent = $('styleGuide');
		onChild = $('styleGuideDropdown');
		$('sgdsLooks').setStyle('color', pink);	
		
	} else if (currentPage.test(/pink_collegiate\/index.jsp/)) {
		
		onParent = $('pinkCollegiate');
		onChild = $('pinkCollegiateDropdown');
		
	} else if (currentPage.test(/pink_collegiate\/school_spirit.jsp/)) {
		
		onParent = $('pinkCollegiate');
		onChild = $('pinkCollegiateDropdown');
		$('pcSpirit').setStyle('color', pink);
		
	} else if (currentPage.test(/pink_collegiate_collection_wallpaper.jsp/)) {
		
		onParent = $('pinkCollegiate');
		onChild = $('pinkCollegiateDropdown');
		$('pcWallpapers').setStyle('color', pink);
		
	} else if (currentPage.test(/campus_reps\/map.jsp/)) {
		
		onParent = $('pinkCollegiate');
		onChild = $('pinkCollegiateDropdown');
		$('pcCampusReps').setStyle('color', pink);
		
	} else if (currentPage.test(/pink_collegiate_collection.jsp/)) {
		
		onParent = $('pinkCollegiate');
		onChild = $('pinkCollegiateDropdown');
		$('pcCollection').setStyle('color', pink);
		
	} else if (currentPage.test(/pcc\/showdown.jsp/)) {
		
		onParent = $('pinkCollegiateCollection');
		onChild = $('pinkCollegiateCollectionDropdown');
		$('pccdsCollegiateShowdown').setStyle('color', pink);
		
	} else if (currentPage.test(/pink_collegiate_collection_wallpaper.jsp/)) {
		
		onParent = $('pinkCollegiateCollection');
		onChild = $('pinkCollegiateCollectionDropdown');
		$('pccdsWallpapers').setStyle('color', pink);
		
	} else if (currentPage.test(/pink_nation/)) {
		onParent = $('pinkNation');
	} else if (currentPage.test(/index.jsp/) || location.href.charAt(location.href.length-1) == "/" ) {
		onParent = $('homePage');
	} else {
		onParent = null;
		onChild = null;
	}
	
	setOn();
	
	// TODO: do we need to init homepage and pinknation? hmm...
	initParentChild($('homePage'), $('homeDropdown'));
	initParentChild($('styleGuide'), $('styleGuideDropdown'));
	initParentChild($('pinkCollegiate'), $('pinkCollegiateDropdown'));
//	initParentChild($('pinkCollegiateCollection'), $('pinkCollegiateCollectionDropdown'));
//	initParentChild($('onCampus'), $('onCampusDropdown'));
	initParentChild($('pinkNation'), $('pinkNationDropdown'));

}

addEvent(window, 'load', subscribe_nav);
