$.fn.serializeObject = function()
{
    var o = {};
    var a = this.serializeArray();
    $.each(a, function() {
        if (o[this.name]) {
            if (!o[this.name].push) {
                o[this.name] = [o[this.name]];
            }
            o[this.name].push(this.value || '');
        } else {
            o[this.name] = this.value || '';
        }
    });
    return o;
};



$(document).ready(function() {

    var home_slide = $("#home_slide");
    var partyPics = $("#partyPics");
    var dancerMain = $("#dancerMain_slider");
    var sliding_gallery = $("#sliding_gallery");
    var photo_slider = $('#photo_slider');

  	$('.validate').validate();

  	if(home_slide) {
      $(home_slide).cycle({
  	    fx: 'fade',
  	    height: 226
      });
    }

  	if(partyPics) {
    	$("#partyPics").jCarouselLite({
    		vertical: false,
    		visible: 4,
    		auto:3000,
    		speed:1500,
    		btnNext: ".next",
    		btnPrev: ".prev",
    		mouseWheel: true
    	});
    }

  	if(dancerMain) {
      $(function() {
      	$("#dancerMain_slider").jCarouselLite({
      		vertical: false,
      		visible: 1,
      		auto:0,
      		speed:1500,
      		btnNext: ".next",
      		btnPrev: ".prev",
      		mouseWheel: true
      	});
      });
    }


  	if(photo_slider) {
      $('#photo_slider').cycle({
      	fx: 'turnDown',
          timeOut: 4000
      });
    }

  	if(sliding_gallery) {
  	  $("#sliding_gallery").cycle('fade');
    }

  	$(function() {
  		$('.lightbox').lightBox({
	        fixedNavigation:true,
	    	  imageBtnPrev: '/resources/3rdparty/lightbox/images/lightbox-btn-prev.gif',
	        imageBtnNext: '/resources/3rdparty/lightbox/images/lightbox-btn-next.gif',
	    	  imageBtnClose: '/resources/3rdparty/lightbox/images/lightbox-btn-close.gif',
	        imageLoading: '/resources/3rdparty/lightbox/images/lightbox-ico-loading.gif'
  	    });
  	});

  	$(function() {
  		$('.galleryimage').lightBox({
          fixedNavigation:true,
          imageBtnPrev: '/resources/3rdparty/lightbox/images/lightbox-btn-prev.gif',
          imageBtnNext: '/resources/3rdparty/lightbox/images/lightbox-btn-next.gif',
          imageBtnClose: '/resources/3rdparty/lightbox/images/lightbox-btn-close.gif',
          imageLoading: '/resources/3rdparty/lightbox/images/lightbox-ico-loading.gif'
  	    });
  	});


    $(function() {
    	$(".newsticker-jcarousellite").jCarouselLite({
      	vertical: true,
      	visible: 1,
      	auto:3000,
      	speed:1500,
      	btnNext: ".next",
      	btnPrev: ".prev",
      	mouseWheel: true
    	});
    });


    $('.scrollLeft').cycle({
    	fx: 'scrollLeft',
    	height: 326
    });



    /* gallery page */
       $("#photogallery div").quickpaginate({ perpage: 4, showcounter: true, pager : $(".paginate_counter") });
       $(".toggle span.entry").quickpaginate({ perpage: 4, showcounter: true, pager : $(".paginate_counter") });

     //this is for the slider on the home page
         $(".gallery_pic .gallery_pic2").hover(
                 function () {
                     $(this).css("border","4px solid #fdba09");
                 },
                 function () {
                     $(this).css("border","4px solid #ffffff");
                 }
         );


});

function ajaxProcessForm(form_id, form_name, form_action, form_method){

	var formData = $('#'+form_id).serializeObject();
	formData['form_url'] = form_name;
	var feedback = form_name+'_feedback';
	var ajaxresult = form_name+'_ajaxResult';

	$.ajax({
		url: form_action,
		type: form_method,
		dataType: 'json',
		data: formData,
		success: function(response) {
			if(!response.errors) {
				$('#'+feedback).hide();
				$('#'+ajaxresult).html(response.message);
				$('#'+ajaxresult).attr('title', 'Thank you for filling out the form');
				$('#'+ajaxresult).dialog();
			}
			else {
				$('#'+feedback).html(response.errors).show();
			}
		}
	});

}