/* 
	Carta - Javascript initialization
*/

jQuery.noConflict()

jQuery(document).ready(function($){
	
	/* 
		Cufon text replacement
		http://wiki.github.com/sorccu/cufon/
	*/
	Cufon.replace('#menu strong, #toolbar strong, .pag strong, h1:not(.classic), h2:not(.classic), h3:not(.classic), h4:not(.classic), h5:not(.classic), h6:not(.classic), a#sign-promo');
	Cufon.replace('.pagination .emph', { textShadow: '0 1px rgba(0, 0, 0, 0.3)' });
	
	/* 
		Superfish dropdown menu
		http://users.tpg.com.au/j_birch/plugins/superfish/
	*/ 
	$("ul#menu, #toolbar ul").superfish({
		delay: 500,
		autoArrows: false,
		speed: 150,
		animation: { opacity: 'show', height: 'show' }
	})
	
	/* CSS fixes for old browsers */
	$("ul#menu li:last-child").css({
		"background": "none",
		"padding-right": 0
	})
	
	/* Gallery scripts call */
	galleria()
	
	/* Contact form call */
	$("form#contact-form").wbform({
		str: {
			general: "Please, fill out all required fields properly.",
			email: "Please, enter a valid email address.",
			website: "Please, enter a valid website url.",
			success: "Thank you! We have received your message.",
			unexpected: "An error occured. Please, try again later."
		}
	})
	
	/* Search bar style toggle */
	$("#toolbar #search-form .input-text").focus(function(){
		$(this).addClass("focus")
	}).blur(function(){
		if ($(this).val().length < 1) $(this).removeClass("focus")
	})
	
	/* Input's labels system */
	$(".focus-label").each(function(){
		var field = $(this),
			label = field.attr("title"),
			original = {
				"color": field.css("color"),
				"font-style": field.css("font-style")
			},
			labelstyle = {
				"color": "#868686",
				"font-style": "italic"
			}
			
		field
			.val(label)
			.css(labelstyle)
			.addClass("labeled")
			.focus(function(){
				if (field.hasClass("labeled"))
					field
						.val("")
						.removeClass("labeled")
						.css(original)
			})
			.blur(function(){
				if (!field.val().length)
					field
						.val(label)
						.addClass("labeled")
						.css(labelstyle)
			})
	})
	
	/* Detecting Internet explorer 6 */
	var ie6 = (navigator.userAgent.indexOf("MSIE 6") >= 0) ? true : false
	
	/* Messages closing */
	if (!ie6) {
		$(".message:not(.sticky)").prepend('<a class="close" href="#">Close</a>');
		$(".message .close").click(function(){
			$(this).parent(".message").delay(100).slideUp(250)
			return false
		})
	}
	
	/* Internet explorer 6 transparency */
	if (ie6) DD_belatedPNG.fix('img, h1#logo, .drop-shadow, #footer #note, a#sign-promo, #toolbar strong, a#subscribe, span.meta')
	
	/*
		Fancybox lightbox
		http://fancybox.net/
	*/
	$("a.zoom").fancybox({
		'titleShow': false,
		'transitionIn': 'elastic',
		'transitionOut': 'elastic',
		'easingIn': ($.easing.def) ? "easeOutBack" : "swing",
		'easingOut': ($.easing.def) ? "easeOutBack" : "swing",
		'overlayShow': false
	})
	$("a.fullzoom").fancybox({
		'transitionOut': 'elastic',
		'width': '90%',
		'height': '95%',
		'overlayShow': true,
		'overlayColor': '#000',
		'overlayOpacity': 0.5,
		'centerOnScroll': true
	});
	
	/*
		Gallery scripts
	*/
	function galleria(){
	
		/* Apply "nopic" class to items without images */
		$(".gallery .entry:not(:has(img))").addClass("nopic");
		
		$(".gallery .entry:not(.nopic)").hover(function(){
		
			$(this)
				.find("img")
				.animate({ 
					marginTop: "-" + $(this).find("span").height()
				}, { 
					queue: false, 
					easing: ($.easing.def) ? "easeOutExpo" : "swing"
				})
			$(this)
				.find(".title")
				.stop(true, true)
				.animate({ 
					bottom: "-35px"
				}, { 
					easing: ($.easing.def) ? "easeOutExpo" : "swing"
				})
				
		}, function(){
				
			$(this)
				.find("img")
				.animate({
					marginTop: "0"
				}, { 
					queue: false, 
					easing: ($.easing.def) ? "easeOutBounce" : "swing"
			})
			$(this)
				.find(".title")
				.animate({
					bottom: "10px"
				}, 150)
				
		})
		
	}
	
	$(window).load(function(){
		
		/* Accordion call */
		$("#featured").wbaccordion()
				
	})
	
})
