
// remap jQuery to $
//$.(document).ready(function(){
$(document).ready(function(){
//$('#fancyGallery').fancygallery({boxOptions: {animationSpeed:'slow',theme:'light_rounded'}});	
$('#fancyGallery').fancygallery({thumbHeight:160,width:630,height:700, columnOffset:20,thumbOpacity:1,rowOffset:50,imagesPerPage:6, backgroundColor:'#38598c', boxOptions: {animationSpeed:'slow',theme:'light_rounded'}});
$("#featured > ul").tabs({fx:{opacity: "toggle"}}).tabs("rotate", 5000, true);

   $(function() {
        $("#leftCall").live('click', function(event) {
            $(this).addClass("selected").parent().append('<div class="messagepop pop"><form method="post" id="new_message" action="/messages"><p><label for="name">Your Name</label><input type="text" size="30" name="name" id="name" /></p><p><label for="phone">Your Number</label><input type="text" size="30" name="phone" id="phone" /></p><p><label for="body">Message</label><textarea rows="6" name="body" id="body" cols="35"></textarea></p><p><input type="submit" value="Send Message" name="commit" id="message_submit"/> or <a class="close" href="/">Cancel</a></p></form></div>');
            $(".pop").slideFadeToggle()
            $("#email").focus();
            return false;
        });

        $(".close").live('click', function() {
            $(".pop").slideFadeToggle();
            $("#leftCall").removeClass("selected");
            return false;
        });
    });

    $.fn.slideFadeToggle = function(easing, callback) {
        return this.animate({ opacity: 'toggle', height: 'toggle' }, "fast", easing, callback);
    }; 

	//$('#js-news').ticker();
$(".fade img").hover(

function() {

$(this).stop().animate({"opacity": "0.6"}, "slow");

},

function() {

$(this).stop().animate({"opacity": "1"}, "slow");

});
$('form.iphorm').iPhorm();
	
	// Tooltip settings
	if ($.isFunction($.fn.qtip)) {
		$('.iphorm-tooltip').qtip({
			content: {
				text: false
			},
			style: {
				tip: 'leftMiddle',
				name: 'blue'
			},
			position: {
				corner: {
					target: 'rightMiddle',
					tooltip: 'leftMiddle'
				}
			}
		});
	}
	
	var subjectHtml = $('.subject-input-wrapper').html();
	
	$('#subject').live('change', function () {		
		if ($(this).val() == 'Other') {
			$('.subject-input-wrapper').empty();
			newHtml = $('<input name="subject" type="text" id="subject" value="" />');
			$('.subject-input-wrapper').html(newHtml);
			$cancelOther = $('<a>').click(function () {
				$('.subject-input-wrapper').empty();
				$('.subject-input-wrapper').append(subjectHtml);
				$(this).remove();
				return false;
			}).attr('href', '#').addClass('cancel-button').attr('title', 'Cancel');
			newHtml.after($cancelOther);
		}
	});


//for the commenting system
	/* The following code is executed once the DOM is loaded */
	
	/* This flag will prevent multiple comment submits: */
	var working = false;
	
	/* Listening for the submit event of the form: */
	$('#addCommentForm').submit(function(e){

 		e.preventDefault();
		if(working) return false;
		
		working = true;
		$('#submit').val('Working..');
		$('span.error').remove();
		
		/* Sending the form fileds to submit.php: */
		$.post('_cms_submit.php',$(this).serialize(),function(msg){

			working = false;
			$('#submit').val('Submit');
			
			if(msg.status){

				/* 
				/	If the insert was successful, add the comment
				/	below the last one on the page with a slideDown effect
				/*/

				$(msg.html).hide().insertBefore('#addCommentContainer').slideDown();
				$('#body').val('');
			}
			else {

				/*
				/	If there were errors, loop through the
				/	msg.errors object and display them on the page 
				/*/
				
				$.each(msg.errors,function(k,v){
					$('label[for='+k+']').append('<span class="error">'+v+'</span>');
				});
			}
		},'json');

	});
   $('.slideshow').cycle({
	fx:    'fade', 
    speed:  4500,
	 pause:  1 
	});
	
	//footer form validation
	// $("#requestCall").validate();
	
	
	    function shakeIt() {
    $("#callBackBtn").show('shake', 55);
    return false;
}


$("#requestCall").validate({
 
    invalidHandler: function(form, validator) {
        shakeIt();
    },
	
			messages: { 
                        "name": "", 
                        "phone": "", 
                }
});	
	
	
//	$('#logo').click(function(){
 // window.location = 'http://www.meadspark.com/';
//});
	
//$("#requestCall").validate({
// 
//    invalidHandler: function(form, validator) {
//        shakeIt();
//    },
//	success: function(label) {
//				label.text("ok!").addClass("success");
//			},
//			errorElement: "div",
//        wrapper: "div",  // a wrapper around the error message
//        errorPlacement: function(error, element) {
//            offset = element.offset();
//            error.insertBefore(element)
//            error.addClass('message');  // add a class to the wrapper
//            error.css('position', 'absolute');
//            error.css('left', offset.left + element.outerWidth());
//            error.css('top', offset.top);
//        }
//});
if ($('#cmsVideo').length) {
$('#cmsImages').hide();
$('#vid a').addClass('active');

$('#img a').click(function() {
//$('#flashcontent').toggle(400);
$('#cmsVideo').fadeOut("fast", function() {
$('#cmsImages').fadeIn("slow");});



$(this).addClass('active');
$('#vid a').removeClass('active');
return false;
});

$('#vid a').click(function() {
//$('#flashcontent').toggle(400);
$('#cmsImages').fadeOut("fast", function() {
$('#cmsVideo').fadeIn("slow");});


$(this).addClass('active');
$('#img a').removeClass('active');
return false;
});
}

})(this.jQuery);
//});


//$(document).ready(function(){
//init here the plugin
//$('#fancyGallery').fancygallery({thumbHeight:160,width:630,height:700, columnOffset:20,thumbOpacity:1,rowOffset:50,imagesPerPage:6, backgroundColor:'#194aa6', boxOptions: {animationSpeed:'slow',theme:'light_rounded'}});
//});

//Image preloader
var images = new Array(
	'/contact-form/images/close.png',
	'/contact-form/images/success.png'
);
var imageObjs = new Array();
for (var i in images) {
	imageObjs[i] = new Image();
	imageObjs[i].src = images[i];
}
