jQuery.noConflict();
jQuery(document).ready(function($){
	$('body').addClass("JS").removeClass("noJS");
	
	//prevent console.log calls from generating errors if console is not available
	//see http://stackoverflow.com/questions/1114187/is-it-a-bad-idea-to-leave-firebug-console-log-calls-in-your-producton-javascrip/1114200#1114200
	if(typeof console === "undefined") {
	    console = { log: function() { } };
	}

	/* --------------- dropdown menu --------------- */
    $("#nav li:has(ul)").addClass("hasChild");

	/* --------------- lazyload --------------- */
	 $('img').filter(':not(.slider img, .pager img, .zoom img, .portfolio-content .post img)').lazyload({
     	placeholder : "img/grey.gif",       
     	effect      : "fadeIn"
 	});
	/* --------------- jqtransform --------------- */
	//style forms only for IE version greater than 8.0, or else other browsers
	if(($.browser.msie && $.browser.version>=8.0) || !$.browser.msie){
		$("form").jqTransform();
		$("label:not(.screen-reader-text)").inFieldLabels();
	}	

	/* --------------- required form fields --------------- */
	$("input.required").focus(function(){
		var req=$(this).parents(".form-item").find(".form-required");
		req.animate({width: 'hide'}, 200);
	});
	$("input.required").blur(function(){
		var req=$(this).parents(".form-item").find(".form-required");
		if(!$(this).val()){
			req.animate({width: 'show'}, 350);
		}
	});	
	
	//zoom indicator show/hide
	
	//add .has-zoom class and .zoom span to content image links
	$(".entry-content a").each(function(){
		var url=$(this).attr("href");
		var ext=url.substring(url.length-3, url.length);
		if(ext=="png" || ext=="jpg" || ext=="gif"){
			$(this).addClass("has-zoom");
			if($(this).parent().hasClass("wp-caption")){
				$(this).append('<span class="zoom">View larger image</span>');
			}
		}
	});
	
	
	setZoom=function(){
		$(".has-zoom").hover(
			function(){
				$(this).find(".zoom").animate({
				    top: '0px',
				    right: '0px'
	  			}, "fast");
			},
			function(){				
				$(this).find(".zoom").animate({
				    top: '-40px',
				    right: '-40px'
	  			}, "fast");
			}
		);
		//fancybox
		$("a.has-zoom").fancybox({
			overlayOpacity:0.7,
			overlayColor:"#000",
			padding:0,
			margin:50,
			hideOnContentClick: true,
			showCloseButton: false,
			autoScale: false
		});
	};
setZoom();
	
	//image caption show/hide
	
	setCaptions=function(){
		$(".caption").hide();	
		$(".has-caption").hover(
			function(){
				$(this).find(".caption").slideDown("fast");
			},
			function(){
				$(this).find(".caption").slideUp("fast");
			}
		);
	};
	setCaptions();


});