/*////////////////////////////////////////////////////////////////////////////////////////////////////
/// JAVASCRIPT FOR fgcentre.com //////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////*/

/*/ VARIABLES //////////////////////////////////////////////////////////////////////////////////////*/
var KIN = {};

KIN.currentSub = '';
KIN.currentBillboard = 0;
KIN.slideTime = 1500;
KIN.currentPromo = '';
KIN.promoOpen = false;
/*/ end VARIABLES //////////////////////////////////////////////////////////////////////////////////*/

/*/ CLASSES ////////////////////////////////////////////////////////////////////////////////////////*/

/*/ end CLASSES ////////////////////////////////////////////////////////////////////////////////////*/

/*/ FUNCTIONS //////////////////////////////////////////////////////////////////////////////////////*/
KIN.modal = function(param) {
	if(param == 'open') {
		$('#modal, #modal-wrap').css('opacity', 0).addClass('visible');
		$('#modal').stop().animate({'opacity': 1}, 500, 'easeOutQuad', function(){
			$('#modal-wrap').stop().animate({'opacity': 1}, 500, 'easeOutQuad', function(){
			});
		});
	} else {
		$('#modal-wrap').stop().animate({'opacity': 0}, 500, 'easeOutQuad', function(){
			$('#modal').stop().animate({'opacity': 0}, 500, 'easeOutQuad', function(){
				$('#modal').removeClass('visible');
			});
		});
	}
}

KIN.contactSlide = function(direction) {
	if($.browser.msie && $.browser.version <= 7) {
		if(document.getElementById('requesttype').value == 'Service'){
			$('.service').css('display', 'block').slideUp(0).slideDown(500);
		} else {
			$('.service').slideUp(500, function(){
				$('.service').css('display', 'none');
				$('.service input').val('');
				$('.service select').val('0');
				$('.service textarea').val('');
			});
		}
	} else {
		if($('form[name=contact-us] select[name=requesttype]').val() == 'Service'){
			$('.service').css('display', 'block').slideUp(0).slideDown(500);
		} else {
			$('.service').slideUp(500, function(){
				$('.service').css('display', 'none');
				$('.service input').val('');
				$('.service select').val('0');
				$('.service textarea').val('');
			});
		}
	}
}

KIN.initialize = function(divID, lat, long) {
	var mapTitle = $('#' + divID).attr('title').split(',');
	
	var myLatlng = new google.maps.LatLng(lat, long);
	
	var myOptions = {
		zoom: 15,
		center: myLatlng,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	}
	
	var map = new google.maps.Map(document.getElementById(divID), myOptions);
	
	var marker = new google.maps.Marker({
		position: myLatlng,
		title: mapTitle[0]
	});
	
	// To add the marker to the map, call setMap();
	marker.setMap(map);
	
	var contentString = '<div><h3>' + mapTitle[0]  + '</h3><p>' + mapTitle[1] + '<br>' + mapTitle[2] + ', ' + mapTitle[3] + '<br><br>' + mapTitle[4] + '</p></div>';

	var infowindow = new google.maps.InfoWindow({
	    content: contentString
	});
	
	infowindow.open(map,marker);
	
	google.maps.event.addListener(marker, 'click', function() {
		infowindow.open(map,marker);
	});
}
/*/ end FUNCTIONS //////////////////////////////////////////////////////////////////////////////////*/

/*/ DOMREADY  //////////////////////////////////////////////////////////////////////////////////////*/
$(function(){
	/*/ NAVIGATION /*/
	$('.subnav').each(function(index, element){
		$(element).mouseenter(function(){
			$(document).stopTime('hide-sub');
			
			$('.submenu').each(function(i, el){
				if(i != index){
					$(el).css('display', 'none');
				}
			});
			//$('#submenu_' + index).css('display', 'block').stop().animate({'opacity': 1}, 500, 'easeOutQuad');
			$('#submenu_' + index).css('display', 'block');
			
			$('#subnavigation').stop().animate({
				'height': '40px'
			}, 500, 'easeOutQuad');
			KIN.currentSub = index;
		});
		
		$(element).mouseleave(function(){
			$(document).oneTime(KIN.slideTime, 'hide-sub', function(){
				$('#subnavigation').stop().animate({'height': '0px'}, 500, 'easeOutQuad', function(){
					$('#submenu_' + index).css('display', 'none');
				});
			});
		});
	});
	
	$('#subnavigation').mouseenter(function(){
		$('.subnav:eq(' + KIN.currentSub + ')').addClass('hover');
		$(document).stopTime('hide-sub');
	});
	
	$('#subnavigation').mouseleave(function(){
		$('.subnav:eq(' + KIN.currentSub + ')').removeClass('hover');
		$(document).oneTime(KIN.slideTime, 'hide-sub', function(){
			$('#subnavigation').stop().animate({'height': '0px'}, 500, 'easeOutQuad');
		});
	});
	
	$('#navigation ul a').mouseenter(function(){
		if($(this).attr('class') != 'subnav') {
			$('#subnavigation').stop().animate({'height': '0px'}, 500, 'easeOutQuad');
			$(document).stopTime('hide-sub');
		}
	});
	/*/ end NAVIGATION /*/
	
	/*/ SITE SEARCH /*/
	$('#sitesearch input[type=text]').focus(function(){
		$(this).css('background-position', '-2px 20px');
	});
	
	$('#sitesearch input[type=text]').blur(function(){
		if($(this).val() == '' || $(this).val() == undefined) {
			$(this).css('background-position', '-2px 0px');
		}
	});
	/*/ end SITE SEARCH /*/
	
	/*/ SUBSCRIBE /*/
	$('#subscribe-box input[type=text]').focus(function(){
		$(this).addClass('active');
		if($(this).val() == 'Name' || $(this).val() == 'Email') {
			$(this).val('');
		}
	});
	
	$('#subscribe-box input[type=text]').blur(function(){
		if($(this).val() == ''){
			$(this).removeClass('active');
			$(this).val($(this).attr('alt'));
		}
	});
	//*/ end SUBSCRIBE /*//
	
	/*/ BILLBOARD /*/
	if($('body').attr('id') == 'home') {
		$(document).everyTime(5000, 'billboard-timer', function(){
			$('#billboard .billboard').each(function(index, element){
				$(element).removeClass('active');
			});
			
			if(KIN.currentBillboard < $('#billboard .billboard').length){					
				$('#billboard .billboard:eq(' + KIN.currentBillboard + ')').addClass('active').animate({'left':(KIN.currentBillboard * 33) + 'px'}, 500, 'easeOutQuad');
			} else {
				$('#billboard .billboard:eq(0)').addClass('active');
				$('#billboard .billboard').each(function(index, element){
					if(index > 0) {
						$(element).removeClass('active').stop().animate({'left':((index * 33) + 795) + 'px'}, 500, 'easeOutQuad');
					}
				});
				
				KIN.currentBillboard = 0;
			}
			
			KIN.currentBillboard++;
		});
		
		$('#billboard .billboard').each(function(index, element){
			$(element).children('.button').click(function(e){
				e.preventDefault();
				
				$(document).stopTime('billboard-timer');
				
				$('#billboard .billboard').each(function(i, elem){
					$(elem).removeClass('active');
					
					$(element).addClass('active');
					
					if(i <= index) {
						$(elem).stop().animate({'left':(i * 33) + 'px'});
					} else {
						$(elem).stop().animate({'left':((i * 33) + 795) + 'px'});
					}
				});	
			});
		});
	}
	/*/ end BILLBOARD /*/
	
	/*/ PROMOTIONS /*/
	$('#promotion-bar a').each(function(index, element){
		if(KIN.promoOpen) {
			thisTimeout = 0;
		} else {
			thisTimeout = 200;
		}
		
		hiConfig = {
	        sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)
	        timeout: thisTimeout, // number = milliseconds delay before onMouseOut
	        over: function() {
	        	var divHeight = $('#promotion-' + $(element).attr('rel')).height();
	        	
				$(document).stopTime('hide-promotion');
				$('.promotion-pointer').css('display', 'none');
				$('#promotion-holder .promotion').css('display', 'none');
				$(this).children('div').children('.promotion-pointer').css('display', 'block');
				
				$('.promotion:eq(' + index + ')').css('display', 'block');
				
				KIN.promoOpen = true;
	        }, // function = onMouseOver callback (REQUIRED)
	        out: function() {
	        	$(document).stopTime('hide-promotion');
				$(document).oneTime(KIN.slideTime, 'hide-promotion', function(){
					$('.promotion-pointer').css('display', 'none');
					$('.promotion:eq(' + index + ')').css('display', 'none');
				});
	        } // function = onMouseOut callback (REQUIRED)
	    }
	    
	    $(element).hoverIntent(hiConfig);
	});
	
	$('#promotion-holder .promotion').each(function(i, elem){
		$(elem).mouseover(function(){
			//alert('ENTER');
			$(document).stopTime('hide-promotion');
		});
		
		$(elem).children().mouseenter(function(){
			$(document).stopTime('hide-promotion');
		});
		
		$(elem).mouseleave(function(){
			//alert('LEAVE');
			$(document).oneTime(KIN.slideTime, 'hide-promotion', function(){
				$('.promotion-pointer').css('display', 'none');
				$('.promotion:eq(' + i + ')').css('display', 'none');
			});
		});
	});
	/*/ end PROMOTIONS /*/
	
	/*/ MODAL /*/
	$(window).scroll(function(){
       $("#modal").css('margin-top', $(window).scrollTop() + 'px');
	});
	
	$('#modal-wrap').draggable({handle: 'h2'});
	
	$('#modal .x').click(function(e){
		e.preventDefault();
		KIN.modal('close');
	});
	
	$('.get-quote').click(function(e){
		e.preventDefault();
		KIN.modal('open');
	});
	/*/ end MODAL /*/
	
	/*** SELECT BOXES ***/
	/*
$('select').selectmenu({
		style: 'dropdown',
		maxHeight: 225
	});
*/
	/*** END SELECT BOXES ***/
	
	/*/ MACHINES /*/
	$('.machine-thumbnail').click(function(e){
		e.preventDefault();
		href = $(this).attr('href');
		$('.machine-image a').attr('href', href);
		$('#machine-image').attr('src', href);
		$('.view-larger').attr('href', href);
	});
	
	$('.print').click(function(e){
		e.preventDefault();
		window.print();
	});
	/*/ end MACHINES /*/
	
	/*/ CONTACT FORM /*/
	$('input[name=repair_date]').datepicker({
		dateFormat: 'yy-mm-dd',
		showAnim: 'drop'
	});
	
	$('.career-body').slideUp(0);
	
	/*
if($.browser.msie) {
		$('form[name=contact-us] select').click(function(event){
			alert('go time');
			if($('form[name=contact-us] select[name=requesttype]').val() == 'Service'){
				$('.service').css('display', 'block').slideUp(0).slideDown(500);
			} else {
				$('.service').slideUp(500, function(){
					$('.service').css('display', 'none');
					$('.service input').val('');
					$('.service select').val('0');
					$('.service textarea').val('');
				});
			}
		});
	} else {
		$('form[name=contact-us] select[name=requesttype]').change(function(event) {
			if($('form[name=contact-us] select[name=requesttype]').val() == 'Service'){
				$('.service').css('display', 'block').slideUp(0).slideDown(500);
			} else {
				$('.service').slideUp(500, function(){
					$('.service').css('display', 'none');
					$('.service input').val('');
					$('.service select').val('0');
					$('.service textarea').val('');
				});
			}
		});
	}
*/
	/*/ end CONTACT FORM /*/
	
	/*/ IFRAME /*/
	if($('#iframe').length > 0) {
		$('#iframe').css('height', ($(window).height() - $('#header').height() - 30) + 'px');
		
		$(window).bind('resize', function(){
			$('#iframe').css('height', ($(window).height() - $('#header').height() - 30) + 'px');
		});
	}
	/*/ end IFRAME /*/
});
/*/ END DOMREADY  //////////////////////////////////////////////////////////////////////////////////*/
