﻿
function doStuff(){
	asideResize();
	HeaderNav.init();
	Comments.init();
	Login.init();
};

function asideResize(){
	if(document.getElementById("aside")){
		var objSection = document.getElementById("section");
		var objAside = document.getElementById("aside");
		if((objSection.offsetHeight) > objAside.offsetHeight){
			objAside.style.height = (objSection.offsetHeight)+"px";
		}
	}
}

HeaderNav = {
	params : {
		navObject : '#nav li.subcat',
		children : '#nav ul.children'
	},
	init : function(){
		jQuery(HeaderNav.params.children).each(HeaderNav.subCatWidth);
		HeaderNav.bind();
	},
	subCatWidth : function(){
		//alert(jQuery(this).parent('li').width()+" / "+jQuery(this).width());
		//if(jQuery(this).parent('li').width() > jQuery(this).width()){
			if(jQuery(this).parent('li').attr('id') != 'makeuptips'){
				jQuery(this).width(jQuery(this).parent('li').width()-2);
			}
		//}
	},
	bind : function(){
		jQuery(HeaderNav.params.navObject).hover(function(){
			jQuery(this).addClass("hover");
		},function(){
			jQuery(this).removeClass("hover");
		})
	}
}

Comments = {
	params : {
		comment : "#respond"	
	},
	init : function(){
		if(jQuery(Comments.params.comment).length > 0){
			Comments.manage();	
		}
	},
	manage : function(){
		jQuery(Comments.params.comment).before('<a class="addComment" href="#respond">Add a Comment</a>');
		jQuery(".addComment").bind("click",Comments.show);
		jQuery(Comments.params.comment).hide();
	},
	show : function(){
		jQuery(this).hide();
		jQuery(Comments.params.comment).slideDown(500);
		return false;
	}
}

Login = {
	init : function(){
		var sUrl = window.location.toString();
		//if(sUrl.indexOf('redirect_to') != -1 && sUrl.indexOf('wp-admin') == -1) Login.agreements();
		Login.agreements();
	},
	agreements : function(){
		jQuery(".loginform p:eq(0)").append('<br/><input id="agreement" class="checkbox" type="checkbox" value="ok" name="agreement"/><span>I have read and accept the <a href="/conditions-of-use" target="_blank">Terms of Use</a> and the <a href="/moderation-charter-pro" target="_blank">Moderation Charter</a> of Blog-Make-up.com, and <i>I acknowledge that I am fully aware of the rights that I am granting to Lancôme on the Participant Content.</i></span>');
		jQuery("#wp-submit").bind("click",Login.check);
	},
	check : function(){
		if(jQuery("#agreement:checked").length == 0){
			Login.showError();
			return false
		};
	},
	showError : function(){
		if(jQuery(".loginform p.error").length == 0){
			jQuery(".loginform").before('<p class="error">You have to accept the Conditions of Use to login to the Professionals Area</p>');
		}
	}
}