/**
 * JavaScript code to handle Google Map API
 */
var roadMap;
var panoramaMap;
var doeAnderson = new google.maps.LatLng(38.25712976282249, -85.760840);
var doeAnderson2 = new google.maps.LatLng(38.256945, -85.760919);

function initialize() {
	var mapOptions = {
		center : doeAnderson,
		zoom : 17,
		mapTypeId : google.maps.MapTypeId.ROADMAP,
		streetViewControl : false,
		visible : false
	};

	roadMap = new google.maps.Map(document.getElementById("map"), mapOptions);

	var panoramaOptions = {
		addressControl : false,
		position : doeAnderson,
		pov : {
			heading : 190,
			pitch : 13,
			zoom : 0
		}
	};

	panoramaMap = new google.maps.StreetViewPanorama(document
			.getElementById("map"), panoramaOptions);

	var image = 'images/home-btn.png';

	var markerPanorama = new google.maps.Marker({
		position : doeAnderson2,
		map : panoramaMap,
		icon : image,
		title : 'Doe Anderson - 620 W Main Louisville KY 40202'
	});

	var markerMap = new google.maps.Marker({
		position : doeAnderson2,
		map : roadMap,
		icon : image,
		title : 'Doe Anderson - 620 W Main Louisville KY 40202'
	});

	google.maps.event.addListener(markerPanorama, 'click', function() {
		toggleStreetView();
	});

	google.maps.event.addListener(markerMap, 'click', function() {
		toggleStreetView();
	});
}// End function initialize()

function toggleStreetView() {
	var toggle = panoramaMap.getVisible();
	if (toggle == false) {
		panoramaMap.setVisible(true);
	} else {
		panoramaMap.setVisible(false);
	}// End if (toggle == false)
}// End function toggleStreetView()
/**
 * END JavaScript code to handle Google Map API
 */


/**
 * All other jQuery
 */
$(document).ready(function(){
    $('.slide-out-div').tabSlideOut({
        tabHandle: '.handle',                     //class of the element that will become your tab
        pathToTabImage: 'images/email.png', //path to the image for the tab //Optionally can be set using css
        imageHeight: '122px',                     //height of tab image           //Optionally can be set using css
        imageWidth: '40px',                       //width of tab image            //Optionally can be set using css
        tabLocation: 'right',                      //side of screen where tab lives, top, right, bottom, or left
        speed: 300,                               //speed of animation
        action: 'click',                          //options: 'click' or 'hover', action to trigger animation
        topPos: '50px',                          //position from the top/ use if tabLocation is left or right

        fixedPosition: false                      //options: true makes it stick(fixed position) on scroll
    });	
	
	// borrowed from jQuery easing plugin
	// http://gsgd.co.uk/sandbox/jquery.easing.php
	$.easing.elasout = function(x, t, b, c, d) {
		var s = 1.70158;
		var p = 0;
		var a = c;
		if (t == 0)
			return b;
		if ((t /= d) == 1)
			return b + c;
		if (!p)
			p = d * .3;
		if (a < Math.abs(c)) {
			a = c;
			var s = p / 4;
		} else
			var s = p / (2 * Math.PI) * Math.asin(c / a);
		return a * Math.pow(2, -10 * t)
				* Math.sin((t * d - s) * (2 * Math.PI) / p) + c + b;
	};
	
	$.easing.easeOutQuart = function(x, t, b, c, d) {
		return -c * ((t = t / d - 1) * t * t * t - 1) + b;
	};
	
    $('area.tooltip').cluetip({
        width: 275,
        height: 'auto',
        positionBy: 'bottomTop',
        splitTitle: '|',
        showTitle: false,
        fx: {
            open: 'fadeIn',
            openSpeed:  '500'
		}
	});
    
	$("a[rel=hero_group]", "a[rel=people_group]", "a[rel=print_group]", 
			"a[rel=broadcast_group]", "a[rel=outofhome_group]", "a[rel=interwebs_group]", "a[rel=mobile_group]",
			"a[rel=channelmarketing_group]", "a[rel=direct_group]", "a[rel=design_group]", "a[rel=crm_group]",
			"a[rel=media_group]", "a[rel=pr_group]", "a[rel=socialmedia_group]", "a[rel=bellarmine]",
			"a[rel=centralbank]", "a[rel=daytonabeach]", "a[rel=healingplace]", "a[rel=humana]", "a[rel=independence]", 
			"a[rel=johnsoncontrols]", "a[rel=johnsoncontrols]", "a[rel=makersmark]", "a[rel=purina]", 
			"a[rel=commonwealthofky]", "a[rel=stx]", "a[rel=suntancity]").fancybox({
		'transitionIn'		: 'fade',
		'transitionOut'		: 'fade',
		'titlePosition' 	: 'inside',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
		}
	});
	
	$(".hero-box").fancybox({
		'width'				: 815,
		'height'			: 560,					
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});
	
	$(".top-box").fancybox({
		'width'				: 815,
		'height'			: 560,					
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});
	
	$(".people-box").fancybox({
		'width'				: 345,
		'height'			: 700,
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});

	$(".job-posting").fancybox({
		'width'				: 850,
		'height'			: 670,					
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});
	
	$(".brands-box-opening").fancybox({
		'width'				: 815,
		'height'			: 250,				
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});
	
	$(".brands-box").fancybox({
		'width'				: 815,
		'height'			: 560,					
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});
	
	
	$(".brands-box-video").fancybox({
		'width'				: 775,
		'height'			: 490,						
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});
	
	$(".brands-box-audio").fancybox({
		'width'				: 775,
		'height'			: 130,						
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});
	
	$(".brands-box-banner").fancybox({
		'width'				: 850,
		'height'			: 160,						
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});
	
	$(".what-box-media").fancybox({
		'width'				: 815,
		'height'			: 400,					
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});
	
	$(".what-box-pr").fancybox({
		'width'				: 815,
		'height'			: 250,					
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});
	
	$(".what-box").fancybox({
		'width'				: 815,
		'height'			: 560,					
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});
	
	$(".what-box-video").fancybox({
		'width'				: 775,
		'height'			: 490,						
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});
	
	$(".how-videos").fancybox({
		'width'				: 700,
		'height'			: 490,						
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});
	
	$(".where-videos").fancybox({
		'width'				: 700,
		'height'			: 490,						
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});

	$('#join-jobs').tinyscrollbar();
					
	$('#main-nav a').click(function(){// $.scrollTo works EXACTLY the same
										// way, but scrolls the whole screen
		$.scrollTo( this.hash, 2500, {});
		return false;
	});

	$('.home-button a').click(function(){// $.scrollTo works EXACTLY the same
											// way, but scrolls the whole screen
		$.scrollTo( this.hash, 2500, {});
		return false;
	});
    
    $('.slideshow-people').serialScroll({
        items: 'li',
        prev: '#empSlider a.prev',
        next: '#empSlider a.next',
        offset: -230, // when scrolling to photo, stop 230 before reaching it
						// (from the left)
        start: 1, // as we are centering it, start at the 2nd
        duration: 1500,
        force: true,
        stop: true,
        lock: false,
        cycle: false, // don't pull back once you reach the end
        easing: 'easeOutQuart' // use this easing equation for a funny effect
        // jump: true // click on the images to scroll to them
    });

	$('.slideshow-history').serialScroll({
        items: 'li',
        prev: '#historySlider a.prev',
        next: '#historySlider a.next',
        offset: -230, // when scrolling to photo, stop 230 before reaching it
						// (from the left)
        start: 1, // as we are centering it, start at the 2nd
        duration: 1500,
        force: true,
        stop: true,
        lock: false,
        cycle: false, // don't pull back once you reach the end
        easing: 'easeOutQuart' // use this easing equation for a funny effect
        // jump: true // click on the images to scroll to them
    });

	$('.slideshow-brands').serialScroll({
        items: 'li',
        prev: '#brandSlider a.prev',
        next: '#brandSlider a.next',
        offset: -230, // when scrolling to photo, stop 230 before reaching it
						// (from the left)
        start: 1, // as we are centering it, start at the 2nd
        duration: 1500,
        force: true,
        stop: true,
        lock: false,
        cycle: false, // don't pull back once you reach the end
        easing: 'easeOutQuart' // use this easing equation for a funny effect
        // jump: true // click on the images to scroll to them
    });

	$(".submitbutton").click(function() {
		$('.error').hide();  
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		
		var name = $("input#name").val();
		if (name == "") {
			$("label#name_error").show();
			$("input#name").focus();
			return false;
		}// End if (name == "")

		var email = $("input#email").val();
		if (email == "") {
			$("label#email_error").show();
			$("input#email").focus();
			return false;
		}// End if (email == "")

		// Check email for validity. Prevents email injection as well.
		if(!emailReg.test(email)) {
            $("input#email").after('<span class="error">* Enter a valid email address.</span>');
			return false;
        }// End if(!emailReg.test(email))
		  
		var message = $("textarea#message").val();
		if (message == "") {
			$("label#message_error").show();
			$("textarea#message").focus();
			return false;
		}// End if (message == "")

		dataString = 'name=' + name + '&email=' + email + '&message=' + message;

		$.ajax({
			type: "POST",
			url: "cleanup.php",
			data: dataString,
			success: function() {
				$('#hireus-form').html("<div id='message'></div>");
				$('#message').html("<h2>Contact Form Submitted!</h2>")
				.append("<p>Your email has been sent.<br /> Thank you for your interest in Doe-Anderson.</p>")
				.hide()
				.fadeIn(1500, function() {
					// $('#message').append("<img id='checkmark'
					// src='images/email.png' />");
				}); // End .fadeIn(1500, function()
			}// End success: function() {
		}); // End $.ajax({
		return false;
	});
});
/**
 * END all other jQuery
 */
