jQuery(document).ready(function($){

$(".fwx").live("click", function(_event){
	var url = $(this).attr("href");
	var title = $(this).attr("title");
	var nav_link = $('nav a[href="'+url+'"]');

	if(nav_link.not(".aa")) $(".c").frameworkLoad({type: "a", url: url, replace: false, history: true, history_title: title});

	_event.preventDefault();
});

$(window).bind('popstate', function(_state){
	if(_state.originalEvent.state != null) $(".c").frameworkLoad({type: "a", url: location.href, replace: false, history: false});
});

$(".hs").live("submit" ,function(_event){
	$(".c").frameworkLoad({type: "a", url: $(this).attr("action"), data: {q: $(".hs .sq").val()}, replace: false, history: true});
	$(".hs .sq").val("");
	$(".hs .sq").trigger("blur");

	_event.preventDefault();
});

$("a.tt").hover(function(){
	$(this).append('<div class="t"><div class="ta"></div><div class="tc">'+$(this).attr("title")+'</div></div>');
	var tooltip = $(this).find(".t");

	tooltip.css("top", $(this).outerHeight()-5+"px").css("left", -((tooltip.outerWidth()-$(this).outerWidth())/2)+"px");
	window.setTimeout(function(){tooltip.show()}, 800);

	$(this).removeAttr("title");
}, function(){
	var tooltip = $(this).find(".t");

	$(this).attr("title", tooltip.find(".tc").html());

	tooltip.remove();
});

// Process slider
$(".fader .next").live("click", function(_event){
	$(".fader").fader("next");
});
$(".fader .back").live("click", function(_event){
	$(".fader").fader("back");
});

// Simulate placeholder behaviour
$('input[type="text"], textarea').live("focus",function(){
	if($(this).val() == $(this).attr("placeholder")){
		$(this).val("");
		$(this).css("color", "#333");
	}
});
$('input[type="text"], textarea').live("blur",function(){
	if($(this).val() == ""){
		$(this).val($(this).attr("placeholder"));
		$(this).css("color", "");
	}
	if($(this).parent().hasClass("error")){
		$(this).parent().removeClass("error");
	}
});

// Weight selector
$(".custom-select .toggle").live("click", function(){
	$(this).siblings(".options").show();
	$(this).addClass("active");
});
$(".custom-select .options a").live("click", function(){
	$(this).parent().siblings().removeClass();
	$(this).parent().addClass("selected");
	$(this).closest(".custom-select").find(".toggle .selected").text($(this).attr("data-label"));
	$(this).closest(".custom-select").find("input").val($(this).attr("data-value"));
});

});
