// jQuery Custom Controls v1.0 by DanOlsavsky.com
// Includes jQuery UI and jCarousel Lite controls
// Sorry, but there's global vars. Reference the following to avoid collisions and dont bitch, it's MY code
// FeedMe Parser
//// var content = "";
//// var itemList = "";
//// var descriptionList = new Array();
$(document).ready(function() {

//////////////////////// Custom Core UI - Accordions
	//Accordion
	$(".coreAccordion").customCoreAccordion("slow");
	
//////////////////////// Custom Core UI - Tabs 
	//Tabs
	$(".coreTabs").customCoreTabs();
	
//////////////////////// Custom Core UI - Modal Window w/ Popup - TODO: Make this a plugin 
	//Hide pupup window content
	$(".popupWindow").hide();
	//Select all the anchor tags with name equals to modal
	$('a[rel=modal]').click(function(event) {
		//Cancel the link behavior
		event.preventDefault();
		//Get the anchor id name
		var id = $(this).attr('href');
		//Popup transition effect, quick fade-in, based on anchor id name
		$(id).fadeIn(1);
		//Add the modal mask layer after the body tag
		$('body').append('<div id="mask"></div>');
		//Mask transition effect, slow fade-to
		$('#mask').fadeIn(500);
		centerPopup();
	});
	//Resize the mask on window resize
	$(window).resize(function() {
		centerPopup();
	});
	$(window).scroll(function() {
		centerPopup();
	});
	//If the close button is clicked, close the window
	$('.cancelClose').live('click', function(event) {
		//Cancel the link behavior
		event.preventDefault();
		$('#mask, .popupWindow').hide();
	});
	//Center the popup window and ensure the mask is ... masking everything
	function centerPopup() {
		//Get dimensions
		var windowHeight = $(window).height();
		var windowWidth = $(window).width();
		var documentHeight = $(document).height();
		var documentWidth = $(document).width();
		var scrollTop = $(window).scrollTop();
		var scrollLeft = $(window).scrollLeft();
		var popupHeight = $('.popupWindow').height();
		var popupWidth = $('.popupWindow').width();
		//Center the popup window
		$('.popupWindow').css({
			'top': (windowHeight / 2) - (popupHeight / 2) + scrollTop ,
			'left': (windowWidth / 2) - (popupWidth / 2) + scrollLeft
		});
	
		//Set height and width to mask to fill up the whole screen
		$('#mask').css({
			'height': documentHeight,
			'width': documentWidth
		});
	}
	
//////////////////////// jQuery UI -  Tabs
	// Tabify DIV, add effects, add animation
	$("#mast").tabs({ fx: { opacity: "toggle", duration: "slow"} }).tabs("rotate", 8000, true);
	// Select mast on hover, resume rotation when hover-state is not active
	$("#mast").hover(
		function() {
			$("#mast").tabs("rotate", 0, true);
		},
		function() {
			$("#mast").tabs("rotate", 8000, true);
		}
	);
	//HTML anchors for previous/next button functions
	$('.next').click(function() {
		var $tabs = $('#mast').tabs();
		var selected = $("#mast").tabs("option", "selected");
		//var totalSize = $(".ui-tabs-panel").size();	
		if (selected != 3) {
			$tabs.tabs('select', selected + 1);
		}
		else {
			$tabs.tabs('select', 0);
		}
		return false;
	});
	$('.previous').click(function() {
		var $tabs = $('#mast').tabs();
		var selected = $("#mast").tabs("option", "selected");
		$tabs.tabs('select', selected - 1);
		return false;
	});

//////////////////////// 3rd Party - jCarousel Lite
	$(".carouselVertical").jCarouselLite({
		btnNext: ".next",
		btnPrev: ".prev",
		auto: true,
		speed: 800,
		vertical: true
	 });
	$(".carouselHorizontal").jCarouselLite({
		btnNext: ".next",
		btnPrev: ".prev",
		auto: true,
		speed: 800
	 });
});

//////////////////////// Form
$(document).ready(function(){
$("#contact-form").submit(function(){

var str = $(this).serialize();

   $.ajax({
   type: "POST",
   url: "http://gunbarreldental.com/wp-content/themes/gunbarreldental-theme/form-contact.php",
   data: str,
   success: function(msg){
    
$("#note").ajaxComplete(function(event, request, settings){

if(msg == 'OK') // Message Sent? Show the 'Thank You' message and hide the form
{
result = '<div class="notification_ok">Your message has been sent. Thank you!</div>';
$("#fields").hide();
}
else
{
result = msg;
}

$(this).html(result);

});

}

 });

return false;

});

});

//////////////////////// Yahoo Pipes Feed Parser 
$(document).ready(function() {
	$(".testimonial-description").hide();
	$('h3.itemTitle').click(function(event){
		event.preventDefault();
		$(this).next().slideToggle(100);
	}).toggle( function() {
		$(this).children("span").text("[-]");
	}, function() {
		$(this).children("span").text("[+]");
	});

});
