/**
 * @author amitashckenazi
 */
$mc = jQuery.noConflict();

$mc(document).ready(function(){
	
	
	$mc("ul.sf-menu").supersubs({ 
            minWidth:    12,   // minimum width of sub-menus in em units 
            maxWidth:    27,   // maximum width of sub-menus in em units 
            extraWidth:  0     // extra width can ensure lines don't sometimes turn over 
                               // due to slight rounding differences and font-family 
        }).superfish({ 
            delay:       500,                            // one second delay on mouseout 
            animation:   {opacity:'show',height:'show'},  // fade-in and slide-down animation 
            speed:       'fast'                          // disable drop shadows 
        });
    
    //start galleria
    //http://code.google.com/p/galleria/wiki/Options
    //http://devkick.com/lab/galleria/
    
	if($mc('ul.galleria').length > 0){
		$mc('ul.galleria').galleria({
        history: false, // activates the history object for bookmarking, back-button etc.
        clickNext: true, // helper for making the image clickable
        insert: '#main_image', // the containing selector for our main image
        onImage: function(image, caption, thumb){ // let's add some image effects for demonstration purposes
            // fade in the image & caption
            if (!($mc.browser.mozilla && navigator.appVersion.indexOf("Win") != -1)) { // FF/Win fades large images terribly slow
                image.css('display', 'none').fadeIn(1000);
            }
            //caption.css('display', 'none').fadeIn(1000);
            caption.css('display', 'none');
			
			
            // fetch the thumbnail container
            var _li = thumb.parents('li');
            
            // fade out inactive thumbnail
            _li.siblings().children('img.selected').fadeTo(500, 0.3);
            
            // fade in active thumbnail
            thumb.fadeTo('fast', 1).addClass('selected');
            
            // add a title for the clickable image
            image.attr('title', 'Sigiente imagen >>');
        },
        onThumb: function(thumb){ // thumbnail effects goes here
            // fetch the thumbnail container
            var _li = thumb.parents('li');
            
            // if thumbnail is active, fade all the way.
            var _fadeTo = _li.is('.active') ? '1' : '0.3';
            
            // fade in the thumbnail when finnished loading
            thumb.css({
                display: 'none',
                opacity: _fadeTo
            }).fadeIn(1500);
            
            // hover effects
            thumb.hover(function(){
                thumb.fadeTo('fast', 1);
            }, function(){
                _li.not('.active').children('img').fadeTo('fast', 0.3);
            } // don't fade out if the parent is active
)
        }
    });
    var firstItem = $mc('ul.galleria li:first').addClass('active').find('img').addClass('selected');
    //end galleria
    
	
	
	$mc('#contact-form').jqTransform();
	$mc("button").click(function(){
		$mc(".formError").hide();
	});
	var use_ajax=true;
	$mc.validationEngine.settings={};
	$mc("#contact-form").validationEngine({
		inlineValidation: false,
		promptPosition: "centerRight",
		success :  function(){use_ajax=true},
		failure : function(){use_ajax=false;}
	 })
	$mc("#contact-form").submit(function(e){
			if(!$mc('#subject').val().length){
				$mc.validationEngine.buildPrompt(".jqTransformSelectWrapper","* Este es un campo reuqerido","error")
				return false;
			}
			if(use_ajax){
				$mc('#loading').css('visibility','visible');
				$mc.post('http://mclibrosyarte.com.ar/wp-content/themes/MCasares-default/submit.php',$mc(this).serialize()+'&ajax=1',	
					function(data){
						if (parseInt(data) == -1) {
							$mc.validationEngine.buildPrompt("#captcha", "* Numero de verificacion incorrecto!", "error");
						} else {
							$mc("#contact-form").hide('slow').after('<h1>Gracias!</h1>');
						}	
						$mc('#loading').css('visibility','hidden');
					}
				);
			}
			e.preventDefault();
	})
	//END CONTACT FORM
	}
	
    
	
	//START SLIDING BOXES

	//Caption Sliding (Partially Hidden to Visible)
	$mc('.boxgrid.caption').hover(function(){
		$mc(".cover", this).stop().animate({top:'140px'},{queue:false,duration:100});
	}, function() {
		$mc(".cover", this).stop().animate({top:'205px'},{queue:false,duration:160});
	});
	//END SLIIDNG BOXES
	
	$mc("li.showThumbs").click(function(){
		$mc('.entry').each(function(){
			$mc(this).addClass('thumbView');
		});
	});
	
	$mc("li.showList").click(function(){
		$mc('.entry').each(function(){
			$mc(this).removeClass('thumbView');
		});
	});
	
	
	
	
	
	
	
	
	
    
});

