/* ----------------------------------------------------
Title			: Colorful Places
Version			: V1.0.5
Author			: Bluegreen Creative Group (BGCG)
URL 			: http://www.bgcreativegroup.com/

Description		: Bluegreen travel guides to find travel destinations, vacation experiences, resorts, restaurants and things to do. Plan you next vacation online with us.
Copyright		: Copyright (c)2009-2015 Bluegreen Vacations Unlimited, Inc. All Rights Reserved.

Table of 
Contents		: * - Master JQuery Control
				  A - Featured Content Slider
				  B - Site Feedback Panel
				  C - Add/Remove Articles Widget
				  D - Main Menu Dropdown
				  E - Accordion Menu Toggle
				  F - Popup Menu Control
				  G - Smooth Scroll Control

---------------------------------------------------- */
var iPad = (navigator.userAgent.indexOf('iPad') != -1);
var IE6 = (navigator.userAgent.indexOf("MSIE 6") >= 0);
var Firefox = (navigator.userAgent.indexOf("Firefox") != -1);

/* ----------------------------------------------------
* - Master JQuery Control
---------------------------------------------------- */

$ = jQuery.noConflict();

$(document).ready(function() {

	
	mainSlideshow(); 
	equalColumns();
	//siteFeedback(); 
	addRemoveArticle(); 
	mainmenu(); 
	smoothScroll(); 
	popMenuControl(); 
	accordionMenu(); 
	//badBrowser();		// Affects IE6 ONLY

});

/* ----------------------------------------------------
A - Featured Content Slider
---------------------------------------------------- */
function mainSlideshow() {
	var settings = {
		transition				: 'fade',		// 'slide', 'fade' or 'show' -- 'show' is default
		transition_Direction	: 'horizontal',	// 'horizontal' or 'vertical' --  'horizontal' is default
		transitionSpeed			: 500, 
		displayTime				: 4000, 
		startOnSlide			: 1, 
		autoPlay				: true, 		// Start slideshow playing
		playButton				: true, 		// Show 'Play/Pause' button
		pauseOnHover			: true, 		// Pause slideshow on navigation hover
		directionNav_Build		: true,
		directionNav_Hide		: true,			// Hides directional navigation, returns when hovered
		navigation_Build		: false,		// 'true' = builds navigation for you || 'false' = Use your own navigation 
		navigation_Show			: true 			// NOTE: If no navigation, slideshow will not transition
	};

	var transitionType = (iPad) ? 'slide' : settings.transition;

	// Default tags for Slideshow Window, Slideshow Content and Slideshow Navigation
	var tags = {
		slideWindow				: 'slideshowWindow',
		slide					: 'slideshowContent',
		slideChild				: 'slideshowContent > li',
		nav						: 'slideshowNav',
		navChild				: 'slideshowNav > li',
		directionNav			: 'directionNav',
		directionNavNext_Text	: 'Next',
		directionNavPrev_Text	: 'Previous',
		btn_playPause			: 'PlayPause_Control'
	};

	var slideChild_Length		= $('#' + tags.slideChild).length;
	var navChild_Length			= $('#' + tags.navChild).length;
	var slideTotal				= $('#' + tags.slideChild).size();
	var windowWidth				= $('#' + tags.slideWindow).width();
	var windowHeight			= $('#' + tags.slideWindow).height();

	var slideWidth				= windowWidth * slideTotal;
	var slideHeight				= windowHeight * slideTotal;

	var navChild_Width			= windowWidth / navChild_Length;
	
	var paused					= true;

	function slideshow_SetUp() { 
		if ( transitionType == 'slide' ) {
			$('#' + tags.slideChild).show();
			if ( settings.transition_Direction == 'vertical' ) {
				var startPosition = ( settings.startOnSlide - 1 ) * windowHeight;
				$('#' + tags.slide).css({ 
					'height': slideHeight,
					'top': -startPosition
				});
			} else {
				var startPosition = ( settings.startOnSlide - 1 ) * windowWidth;
				$('#' + tags.slide).css({ 
					'width': slideWidth,
					'left': -startPosition
				});
			}
		} else {
			$('#' + tags.slideChild).hide();
			$('#' + tags.slideChild + ':nth-child('+ settings.startOnSlide + ')').show();
		}
		
		if ( settings.autoPlay ) {
			paused = false; 
			rotateSwitch();
		}
	}

	if ( settings.navigation_Show ) {
		var slideNumber = 1;
	
		if ( !settings.navigation_Build ) {
			$('#' + tags.navChild).each( function(){
				if ( slideNumber <= navChild_Length ) {
					$(this).attr('rel', slideNumber);
					slideNumber++;
				}
			});
		} else {
			var slideshowControl = $('<ul id="' + tags.nav + '"></ul>');
		
			$(slideshowControl).insertAfter('#' + tags.slideWindow);
		
			for ( slideNumber; slideNumber <= slideChild_Length; slideNumber++ ) {
				$('#' + tags.nav).append('<li rel="' + slideNumber + '"><a>' + (slideNumber) + '</a></li>'); 
			}
		}
		
		$('#' + tags.navChild).live('click', function() {	
			if ( !$(this).hasClass('active') ) {
				$active = $(this);
				clearInterval(play);
				rotate();
				rotateSwitch();
			} else { 
				window.location = $(this).find('a').attr('href');
			}
			return false;
		});
		
		// Determine slideshow size and adjust navigation child to fit to 100% width of slideshow content
		if ( !navChild_Length <= 1 || !navChild_Length > 5 ) {
			$('#' + tags.nav).show();
			$('#' + tags.navChild).css({'width':(navChild_Width - 1) });
			$('#' + tags.navChild + ':nth-child('+ settings.startOnSlide + ')').addClass('active');
		}
	}
	
	function slideshow_Play() {
		paused = false;
		clearInterval(play);
		rotateSwitch();
	}

	function slideshow_Paused() {
		paused = true;
		clearInterval(play);
	}
	
	if ( settings.playButton ) { 
		$('<a id="' + tags.btn_playPause + '">Play/Pause Slideshow</a>').insertAfter('#' + tags.slide);

		if ( !settings.autoPlay ) {
			$('#' + tags.btn_playPause).addClass('paused');
		}
		
		$('#' + tags.btn_playPause).click(function() {
			if ( $(this).hasClass('paused') ) {
				settings.autoPlay = true;
				$('#' + tags.btn_playPause).removeClass('paused');
				slideshow_Play();
			} else {
				settings.autoPlay = false;
				$('#' + tags.btn_playPause).addClass('paused');
				slideshow_Paused();
			}
		});
	}
	
	if ( settings.pauseOnHover && settings.autoPlay ) {
		$('#' + tags.navChild).hover(function() {
			slideshow_Paused(); 
		}, function() {
			slideshow_Play(); 
		});
	} else if ( settings.pauseOnHover ) {
		$('#' + tags.navChild).hover(function() {
			slideshow_Paused(); 
		});
	}
	
	if ( settings.directionNav_Build ) {
		if ( !iPad ) {
			var directionControl = $('<div id="' + tags.directionNav + '"><a href="#" id="previous">' + tags.directionNavPrev_Text + '</a><a href="#" id="next">' + tags.directionNavNext_Text + '</a></div>');
			$(directionControl).insertAfter('#' + tags.slideWindow);
			$('#' + tags.directionNav).hide();
		}
		
		if ( !settings.directionNav_Hide ) {
			$('#' + tags.directionNav).show();
		} else { 
			$('#' + tags.slide + ', #' + tags.directionNav).hover(function() { 
				$('#' + tags.directionNav).show();
			}, function() {
				$('#' + tags.directionNav).hide();
			});
		}
			
		$('#' + tags.directionNav + ' a').click(function(e) {
			var btn_Next = ($(this).attr('id')=='next');
			var btn_Previous = ($(this).attr('id')=='previous');
			$active = (btn_Next) ? $('#' + tags.navChild + '.active').next() : $('#' + tags.navChild + '.active').prev();
			
			if ( $active.length == 0 && btn_Next ) {
				$active = $('#' + tags.navChild + ':first');
			} else if ( $active.length == 0 && btn_Previous ) {
				$active = $('#' + tags.navChild + ':last');
			}
			
			animateSlideshow();
			e.preventDefault();
		});
		
		
		/*
		$('#' + tags.slideWindow).touchwipe( {
			wipeLeft: function(e) { 
				$active = $('#' + tags.navChild + '.active').next();
				
				if ( $active.length == 0 ) {
					$active = $('#' + tags.navChild + ':first');
				}
				
				animateSlideshow();
				e.preventDefault();
			},
			wipeRight: function(e) { 
				$active = $('#' + tags.navChild + '.active').prev();
				
				if ( $active.length == 0 ) {
					$active = $('#' + tags.navChild + ':last');
				}
				
				animateSlideshow();
				e.preventDefault();
			}
		});
		*/
		function animateSlideshow() {
			settings.autoPlay = false;
			$('#' + tags.btn_playPause).addClass('paused');
			slideshow_Paused();
			rotate();
		}
	}
	
	function rotate() { 	
		$('#' + tags.navChild).removeClass('active');
		$active.addClass('active');
		
		
		if ( transitionType == 'slide' && settings.transition_Direction == 'vertical' ) {
			var advanceSlide = $active.attr('rel') - 1;
			var slideshowPosition = advanceSlide * windowHeight;

			$('#' + tags.slide).animate({ 
				top: -slideshowPosition
			}, settings.transitionSpeed);
		} else if ( transitionType == 'slide' ) {
			var advanceSlide = $active.attr('rel') - 1;
			var slideshowPosition = advanceSlide * windowWidth;

			$('#' + tags.slide).animate({ 
				left: -slideshowPosition
			}, settings.transitionSpeed);
		} else {
			var advanceSlide = $active.attr('rel');
			$('#' + tags.slideChild).hide();
				
			if ( transitionType == 'fade' ) {
				$('#' + tags.slideChild + ':nth-child(' + advanceSlide + ')').fadeIn(settings.transitionSpeed);
			} else {
				$('#' + tags.slideChild + ':nth-child(' + advanceSlide + ')').show();
			}
		}
	}; 

	function rotateSwitch() { 
		if ( transitionType == 'show' ) {
			var slideshowSpeed = settings.displayTime;
		} else {
			var slideshowSpeed = (settings.displayTime + settings.transitionSpeed);
		}
		
		if ( !paused && settings.autoPlay ) {
			play = setInterval(function() {
				$active = $('#' + tags.navChild + '.active').next();
				if ( $active.length == 0) {
					$active = $('#' + tags.navChild + ':first');
				}
				rotate();
				
			}, slideshowSpeed);
		}
	};
	slideshow_SetUp(); 
}

/* ----------------------------------------------------
  - Column Adjust
---------------------------------------------------- */
function equalColumns() {
	var $adjustColumns = $('#slideshowNav li');
	
	var biggestHeight = 0;
	$adjustColumns.each(function() {
		if( $(this).height() > biggestHeight ) {
			biggestHeight = $(this).height();
		}
	});
	$adjustColumns.height(biggestHeight);
}

/* ----------------------------------------------------
B - Site Feedback Panel
---------------------------------------------------- */
function siteFeedback() {
	$('#feedback').toggle(function() {
		$(this).addClass('active').text('Site Feedback (-)');
		$('#feedback_Panel').slideDown(500);
		return false;
	}, function() { 
		$(this).removeClass('active').text('Site Feedback (+)');
		$('#feedback_Panel').slideUp(500);
		return false;
	});

	$('input[name="contactMe"]').hide();
	var $form = $('form[name="siteFeedback"]');

	$('input[name="q01"]').click(function() {
		var $q01		= $('input[name="q01"]')
		var $q01val		= $('input[name="q01"]:checked').val();
		var $q01answer	= $form.find('#q01a');
		
		$q01answer.parent().show();
		
		if ( $q01val == "Yes" ) {
			$q01answer.children('#q01a_yes').show();
			$q01answer.children('#q01a_no').hide();
		} else {
			$q01answer.children('#q01a_no').show();
			$q01answer.children('#q01a_yes').hide();
		}
	});
	
	
	$('input[name="q02"]').click(function() {
		var $q02		= $('input[name="q02"]')
		var $q02val		= $('input[name="q02"]:checked').val();
		var $q02answer	= $form.find('#q02a');
		
		$q02answer.parent().show();
		
		if ( $q02val == "ownerInterest" ) {
			$q02answer.parent().show();
			$('input[name="submit"]').hide();
			$('input[name="contactMe"]').show();
		} else {
			$q02answer.parent().hide();
			$('input[name="submit"]').show();
			$('input[name="contactMe"]').hide();
		}
	});
	
	/*
	var $formInput = $('form[name="siteFeedback"] input, form[name="siteFeedback"] textarea');
	
	$formInput.focus(function() {
		$(this).addClass('inputFocus').parent().parent().addClass('focus');
	});
	$formInput.blur(function() {
		$(this).removeClass('inputFocus').parent().parent().removeClass('focus');
	});
	*/
}


/* ----------------------------------------------------
C - Add/Remove Articles Widget
---------------------------------------------------- */
function addRemoveArticle() {
	var display			= 5;
	var minimumShow		= 3;

	$('.addRemove').next('ul').find('li').hide();
	var showArticleNumber = 1;
	articleContentLoad();
	
	function articleContentLoad() {
		if ( showArticleNumber <= display ) {
			$('.addRemove').next('ul').find('li:nth-child(' + showArticleNumber + ')').show();
			showArticleNumber++;
			articleContentLoad();
		};
	};
	
	$('.btn_add').click(function(e){
		$(this).parent().next('ul').find('li:hidden:first').show();
		e.preventDefault();
	});
	
	$('.btn_remove').click(function(e){
		if ( ($(this).parent().next('ul').find('li:visible').length) >= minimumShow + 1 ) {
			$(this).parent().next('ul').find('li:visible:last').hide();
			e.preventDefault();
		}
	});
};

/* ----------------------------------------------------
D - Main Menu Dropdown
---------------------------------------------------- */
function mainmenu(){
	$('#navMenu ul').css({'display':'none'}); // Opera Fix
	
	$('#navMenu li').hover(function() { 
		$(this).find('ul:first').css({
			'display':'none',
			'visibility':'visible'
		}).fadeIn(300);
	},function() {
		$(this).find('ul:first').css({
			'visibility':'hidden'
		});
	});
}

/* ----------------------------------------------------
E - Accordion Menu Toggle
---------------------------------------------------- */
function accordionMenu() {
	$('.leftColumn-Content-new li ul').hide();
	$('.leftColumn-Content-new a[href^=#]').click(function(){
		if( $(this).next().is(':hidden') ) {
			$('.leftColumn-Content-new li ul').slideUp();
			$(this).next().slideDown();
		} else {
			$(this).next().slideUp();
		}
		return false;
	});
	
	$('.accordionTitle, h5').click(function() {
		$(this).next('div.accordionContent').slideToggle(300).siblings('div.accordionContent').slideUp('slow');
		$('div.accordionContent_').addClass('accordionContent');
	});
	$('#secondpane p.accordionTitle').mouseover(function() {
		$(this).next('div.accordionContent').slideDown(500).siblings('div.accordionContent').slideUp('slow');
	});
}

/* ----------------------------------------------------
F - Popup Menu Control
---------------------------------------------------- */
function popMenuControl() {
	$('.popMenu').each(function () {
		var distance = 10;
		var time = 250;
		var hideDelay = 0;
		var hideDelayTimer = null;
		var beingShown = false;
		var shown = false;
		var trigger = $('.trigger', this);
		var info = $('.popUpBox', this).css('opacity', 0);
		
		$([trigger.get(0), info.get(0)]).mouseover(function () {
			if (hideDelayTimer) clearTimeout(hideDelayTimer);
			if (beingShown || shown) {
				// don't trigger the animation again
				return;
			} else {
				// reset position of info box
				beingShown = true;

				info.css({
					top:10,
					left:-95,
					display:'block'
				}).animate({
					top: '+=' + distance + 'px',
					opacity: 1
				}, time, 'swing', function() {
					beingShown = false;
					shown = true;
				});
			}

			return false;
		}).mouseout(function () {
			
			if (hideDelayTimer) clearTimeout(hideDelayTimer);
			hideDelayTimer = setTimeout(function () {
				hideDelayTimer = null;
				info.animate({
					top: '+=' + distance + 'px',
					opacity: 0
				}, time, 'swing', function () {
					shown = false;
					info.css('display', 'none');
				});

			}, hideDelay);

			return false;
		});
	});
}


/* ----------------------------------------------------
G - Smooth Scroll Control
---------------------------------------------------- */
function smoothScroll() {
	$('a[href*=#]').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			var $target = $(this.hash);
			$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
			if ($target.length) {
				var targetOffset = $target.offset().top - 10;
				$('html,body').animate({scrollTop: targetOffset}, 500);
				return false;
			}
		}
	});
}

/* ----------------------------------------------------
* - Bad Browser, No Internet Explorer 6 Support
---------------------------------------------------- */
function badBrowser() {
	if (IE6) {
		var browserWarning = '<div id="browserWarning">This website is not supported by the web broswer you are currently using. <br />Please update your browser to <a href="http://getfirefox.com" target="_blank">Mozilla FireFox</a>, <a href="http://www.google.com/chrome/" target="_blank">Google Chrome</a>, <a href="http://www.apple.com/safari/" target="_blank">Apple Safari</a> or a newer version of <a href="http://www.microsoft.com/windows/internet-explorer/default.aspx" target="_blank">Internet Explorer</a>.</div>.<div id="blackOut" />';
		$(browserWarning).prependTo('body');
		
		var barPosition = (($(window).height() / 2) - ($('#browserWarning').height() / 2));
	
		$('html').css({'overflow':'hidden'});
		$('#browserWarning').css({'zIndex':9999, 'position':'absolute', 'top':barPosition + 'px', 'left':'0px', 'width':'100%', 'line-height':'17px', 'margin':'auto 0px', 'padding':'15px 0px', 'color':'#fff', 'fontSize':'13px', 'fontWeight':'bold', 'backgroundColor':'#780000', 'textAlign':'center', 'borderTop':'1px solid #c00', 'borderBottom':'1px solid #300'});
		$('#browserWarning a').css({'color':'#fff', 'textDecoration':'underline'});
		$('#blackOut').css({'z-index':9998, 'position':'absolute', 'top':'0px', 'left':'0px', 'backgroundColor':'#000', 'opacity':'0.85', 'width':'100%', 'height':$(document).height()});
	};
}
