/*
 * @author Joshua Canfield (Code Clarity TM)
 * @description Basic Scripts for Dana V Music Website
 *
 */

// Show Logged In Message
//$(function() {
//    elementid = $("body");
//    if (elementid.hasClass ("logged-in")) {
//        var htmlString = <p>You are logged in to Dana Vachharajani Music, LLC.</p>;
//        $('div#loggedin').fadeIn(1200);
//        $('div#loggedin').text(htmlString);
//    }
//})

$(function() {

// Basic Website Fixes and Modifications
//$(function() {
    if ($('#searchsubmit').length) {
        $('#searchsubmit').addClass("button").addClass("danavbtn");
    }
//});

// Load Frontpage Slider
//$(function() {
    $("#scroller ul").tabs("#panes > div", {
        tabs: 'a',
        current: 'current',
        onBeforeClick: null,
        onClick: null,
        effect: 'default',
        initialIndex: 0,
        event: 'click',
        rotate: true,
        slideUpSpeed: 800,
        slideDownSpeed: 800,
        history: true
    }).slideshow({
        next: '.forward',
        prev: '.backward',
        disabledClass: 'disabled',
        autoplay: true,
        autopause: true,
        interval: 8500,
        clickable: false
    });
//});

if ($('body.page-id-834').length) {
    $(function() {
        $('#featured').orbit({
            animation: 'horizontal-push',                  // fade, horizontal-slide, vertical-slide, horizontal-push
            animationSpeed: 1200,
            timer: true,
            advanceSpeed: 4000,
            pauseOnHover: true,
            startClockOnMouseOut: false,
            startClockOnMouseOutAfter: 1750,
            directionalNav: true,
            captions: true,
            captionAnimation: 'slideOpen', 		 // fade, slideOpen, none
            captionAnimationSpeed: 800,
            bullets: true,
            bulletThumbs: true,
            bulletThumbLocation: 'orbit/',
            // Uncommon Parameters
            wrapperHTML: '<div class="orbit-wrapper span-14" />'
        });
    })
	$(function() {
		$('div.orbit-contentwrapper a.button').bind("click", function() {
			$('div.slider-nav span').css("z-index","0");
		})
		$('a.close-reveal-modal').click(function() {
			$('div.slider-nav span').css("z-index","1000");
		})
	})
}

// Load Full Calendar via Google
if ($('body.page-id-844').length) {
    $('#calendar').fullCalendar({
        events: 'http://www.google.com/calendar/feeds/9idd4u35mqalf1avnfqof9t4n4%40group.calendar.google.com/public/basic',
        eventClick: function(event, e) {
            e.preventDefault();
            /* Variables for Modal Box
            var boxstart = $('<div id="' + event.start + '" class="calendarBox">');
            var modalbox_wrapper = $'<div id="' + nextitemvar + ' "reveal-contentwrapper"');
            var modalbox_header = $'<h2 class="reveal-contenth2">' + event.title + '</h2>');
            var modalbox_content = $'<p class="reveal-contentp">' + event.description + '</p>');
            var modalbox_closebox = $'<a class="close-reveal-modal">×</a>');
            var modalbox_closewrapper = $'</div>');
            var boxclose = $('</div>');
            var modalbox = boxstart + modalbox_wrapper + modalbox_header + modalbox_content + modalbox_closebox + modalbox_closewrapper + boxclose;
            alert(modalbox);
            */
            $('<div id="' + event.id + '" class="calendarBox reveal-contentwrapper">')
                .appendTo('div#calendarModal')
                .wrapInner('<h2 class="reveal-contenth2" />');
                $('div# + event.id').wrapInner('<p class="reveal-contentp"> + event.description + </p>');
                $('div# + event.id').append('<a class="close-reveal-modal">×</a>')
                $('div# + event.id').append('</div>');

            $('div# + event.id').reveal({
                 animation: 'fadeAndPop',                   //fade, fadeAndPop, none
                 animationspeed: 300,                       //how fast animtions are
                 closeonbackgroundclick: true,              //if you click background will modal close?
                 dismissmodalclass: 'close-reveal-modal'    //the class of a button or element that will close an open modal
            });
            window.open(event.url, 'gcalevent', 'width=700,height=600');
            return false;
        },
        loading: function(bool) {
            if (bool) {
                $('#loading').show();
            }else{
                $('#loading').hide();
            }
        }
    });
}

// Load Administrative Staff Horizontal Accordion
if ($('div#admin-accordion').length) {
    $("#admin-accordion").tabs("#admin-accordion div", {
        tabs: 'p',
        effect: 'horizontal'
    });
}

// Article Sharing
$('#article-social-startleft-share').bind("click", function() {
    $('p.article-social-finish').show();
});


// Back to Top
/* Notes- HTML element is included in footer.php and CSS styles are included in custom-plugins.css */
function backtotop() {
    var scroll_timer;
	var displayed = false;
	var $message = $('#backtotop a');
	var $window = $(window);
	var top = $(document.body).children(0).position().top;
	$window.scroll(function () {
		window.clearTimeout(scroll_timer);
		scroll_timer = window.setTimeout(function () {
			if($window.scrollTop() <= top) {
				displayed = false;
				$message.fadeOut(900);
			}
			else if(displayed == false) {
				displayed = true;
				$message.stop(true, true).show().click(function () { $message.fadeOut(700); });
			}
		}, 100);
	});
}
$("body").ready(function() {
    backtotop();
})

// ConstantContact Submit Form
$('#constantcontactform').submit(function() {
    if(this.ea.value == 'example@subscribe.com' || this.ea.value == '') {
        alert('Please enter your email.'); document.getElementById('widget-constantcontactwidget-3-cc_label_email').focus();
        return false;
    }
});
$('#constantcontactemail').bind("blur",function() {
    if (this.value == '') {
        this.value = 'example@subscribe.com';
    }
})
$('#constantcontactemail').bind("focus", function() {
    if (this.value == 'example@subscribe.com') {
        this.value = '';
    }
})

$('#footer-sendmessage, form.contact-form').submit(function(e) {
    var form = $(this);


    var name = form.find('[name="xyzname"]').val();
    var email = form.find('[name="email"]').val();
    var comment = form.find('[name="comment"]').val();

    // Validate
    var errors = [];
    if (name === '') {
      errors.push("Name is required");
    }

    if (email === '') {
      errors.push("Email is required");
    } else if (!/^\S+@\S+$/.test(email)) {
      errors.push("Email is not valid");
    }

    if (comment === '') {
      errors.push("Comment is required");
    }

    if (errors.length > 0) {
      alert(errors.join("\n"));
      return false;
    }

    var button = form.find('[type="submit"]');
    button.attr("disabled", true);
    button.val("Please wait");

    $.post(form.attr("action"), form.serialize(), function(data) {
      form.replaceWith(data);
    });
   return false; 
});

});

