jQuery.noConflict();

var GOA = GOA || {};

(function($) {
    $.fn.tabs = function() {
        var active = $(this).find('li.active');
        $(this).find('li').click(function(){
            $('#' + active.attr('id') + '-content').hide();
            active.removeClass('active');
            active = $(this);
            $('#' + active.attr('id') + '-content').show();
            active.addClass('active');
        });
    }
    $.fn.stars = function() {
        var ratingStars = $(this).find('a.rating');
        ratingStars.hover(function() {
            $(this).prevAll().andSelf().addClass('selected');
        }, function() {
            var $parent = $(this).parent();
            var currentValue = $parent.siblings('input').first().val();
            var $children = $parent.children('a.rating');
            $children.removeClass('selected').each(function(i){
                if ($(this).metadata().value == currentValue) {
                    $(this).prevAll().andSelf().addClass('selected');
                }
            });
        });
        ratingStars.click(function() {
            var optionValue = $(this).metadata().value;
            $(this).parent().siblings('input').first().val(optionValue);
            
            $(this).parent().parent().removeClass('error');
            return false;
        });
    }
    $.fn.validate = function() {
        $(this).submit(function() {
            var validated = true;
            var $form = $(this);
            $form.find('.input-box > input.required-entry, textarea.required-entry').each(function(i){
                var $input = $(this);
                if (!$input.val()) {
                    $input.addClass('validation-failed');
                    validated = false;
                } else {
                    $input.removeClass('validation-failed');
                }
            });
            $form.find('input[type="hidden"].required-entry').each(function(i){
                var $elt = $(this);
                var $parent = $elt.parent();
                if (!$elt.val()) {
                    $parent.addClass('error');
                    validated = false;
                } else {
                    $parent.removeClass('error');
                }
            });

            return validated;
        });
    }
})(jQuery);

GOA.loader = function(){
    var bodyClasses = jQuery('body').attr('class').split(/\s+/);
    jQuery.each(bodyClasses, function(index, value){
        if(value && GOA.load[value]) GOA.load[value].call();
    });
};

GOA.load = {};
GOA.load["catalog-product-view"] = function(){
    jQuery('#tabs').tabs('#tabs-content');
    jQuery('#review-modal')
        .jqm({toTop: true, trigger: '.product-reviews-button'})
        .stars();
    jQuery('#review-form').validate();
};

jQuery(function(){
    GOA.loader();
});

GOA.addVideo = function(){
		window.scrollTo(0,0);
		var bHeight = jQuery(document).height();
		jQuery('#slider').append('<div id="sliderVideo" class="videoBanner" style="width:600px; height:380px; position: absolute; z-index: 9999; text-align: center; background-color: #000;"><iframe src="http://player.vimeo.com/video/29495770?title=0&amp;byline=0&amp;portrait=0&amp;autoplay=1" width="507" height="380" frameborder="0" webkitAllowFullScreen allowFullScreen></iframe></div>');
		
		jQuery('.wrapper').append('<div id="videoBack" class="videoBanner" style="position: absolute; width: 100%; height: '+bHeight+'px; left: 0; top: 0; z-index: 9998; opacity: 0.8; display: block; background: #fff; cursor: pointer;" onclick="jQuery(\'.videoBanner\').remove();"></div>');
}
