
$(document).ready(function(){

		if ($('#hintGallery').length > 0)
		hintGallery("hintGallery");

		$('form[name="qa1form"]').submit(function(){

			var is_error = 0;

			$('form[name="qa1form"] .ttl').remove();
			$('form[name="qa1form"] input[type="text"]').each(function(){
				if( ($(this).attr('id') != 'additionalInfo') && ($(this).val() == "" || ($(this).hasClass('is_email') && !isValidEmail($(this).val()))) ){
					is_error = 1;
					$(this).addClass('errorfield');
				} else {
					$(this).removeClass('errorfield');
				}
				
				$('form[name="qa1form"]').append('<input class="ttl" value="'+$(this).attr("title")+'" name="label['+$(this).attr('name')+']" type="hidden" />');
				
			});
                        
                        if (is_error == 1) {
				alert('Please check the fields marked in red');
			} else {
                        $.post('sendmail.php', $('form[name="qa1form"]').serialize(), function(data) {
                                    //Don't display "Message Sent" alert
                                    //alert(data);
                                    $('#qaForm').html(data);
                            });
                        }

			
			

			return false;
			
		});
		
		
		
		
		

		if ($('#booking_calendar').length > 0) {
			
			if ($('input[name="jsseldate"]').val() != "")
			{
				$('#booking_calendar').datepick( { altFormat: 'yyyy-mm-dd', onHover: dHoverFunc, defaultDate: new Date ( $('input[name="jsseldate"]').val() ) } );
			}
			else
			{
				$('#booking_calendar').datepick( { altFormat: 'yyyy-mm-dd', onHover: dHoverFunc } );
			}
			
			if ($('.homepagecal').length > 0) {
				$('#events').css("padding", "0");
				$('#events').css("height", "280px");
				$('#events').css("width", "250px");
				$('#booking_calendar').css("padding-left", "10px");
				$('#booking_calendar').css("padding-top", "7px");
			}
			
			else {
			
				$('.datepick-inline').css("width", "230px");
				
			}

			$('.hasDatepick').append('<div id="cal_num_events">Select highlighted date for more details</div>');

			if ($('input[name="event_cat"]').val() == '6') { 
				$('.hasDatepick').prepend('<h4>QA Training Calendar</h4>');
			}
			else
			{
				$('.hasDatepick').prepend('<h4>QA Events Calendar</h4>');
			}

			
		}

		$('div.listPerson').hover(function() {
		
			elementId = "#" + $(this).attr("id") + " img.personThumb";
			
			normalThumb = "images/faces/" + $(this).attr("id") + "_default.jpg";
			hoverThumb = "images/faces/" + $(this).attr("id") + "_hover.jpg"
		
			$(elementId).attr("src", hoverThumb);
		}, function() {
			$(elementId).attr("src", normalThumb);
		});
		
		
		$(".newsticker-jcarousellite").jCarouselLite({  
				 vertical: true,  
				 visible: 2,  
				 auto: 4000,  
				 speed: 1000 
		});  


		if ($(".caseSelect").length > 0) {
			$(".caseSelect").change(function(){
				if ($(this).val() != "")
				window.location.href = $(this).val();
			});
		}
		
		$('a.imgz').lightBox({fixedNavigation:true});


		if ($('#imgs').length > 0)
		$('#imgs').cycle({
			fx:      'scrollLeft',
			next:   '#right',
			timeout:  6000
		});
		
	
		
	//select all the a tag with name equal to modal
	$('a[name=modal]').click(function(e) {
		//Cancel the link behavior
		e.preventDefault();
		
		//Get the A tag
		var id = $(this).attr('href');
	
		//Get the screen height and width
		var maskHeight = $(window).height();
		var maskWidth = $(window).width();
	
		//Set heigth and width to mask to fill up the whole screen
		$('#mask').css({'width':maskWidth,'height':maskHeight,'position':'fixed','top':0,'left':0});
		
		//transition effect		
		$('#mask').fadeIn(1000);	
		$('#mask').fadeTo("slow", 0.8);	

		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();
              
		//Set the popup window to center
		$(id).css('position', 'fixed');

		$(id).css('top',  $('#mask').height()/2-$(id).height()/2);
		$(id).css('left', $('#mask').width()/2-$(id).width()/2);
	

		
		//transition effect
		$(id).fadeIn(2000); 
	
	});
	
	//if close button is clicked
	$('.windowSmall .close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();
		
		$('#mask').hide();
		$('.windowSmall').hide();
	});		
	
	//if mask is clicked
	$('#mask').click(function () {
		$(this).hide();
		$('.windowSmall').hide();
	});			
	
	$('.windowLarge .close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();
		
		$('#mask').hide();
		$('.windowLarge').hide();
	});		
	
	//if mask is clicked
	$('#mask').click(function () {
		$(this).hide();
		$('.windowLarge').hide();
	});		
		

  });








	function hintGallery(container) {
		
		jQuery.fn.isChildOfElement = function(b){
			return (this.parents(b).length > 0);
		};

		$('#' + container + ' .hintDiv').each(function(index){
			$(this).attr("id", container+"Div_" + (index+1));
			$("#" + container + "Div_" + (index+1) + " *").attr("rel", container+"Div_" + (index+1));
		});
		
		$('#' + container + ' img').each(function(index){
			$(this).attr("rel", container+"Div_" + (index+1));
			$(this).addClass("hintImg");
			$("#"+container+"Div_" + (index+1) + " div.image").html("<img alt=\"" + $(this).attr("alt") + "\" src=\"" + $(this).attr("src") + "\" />");
		});
		

		$(document).mouseover(function(event){

				if ($(event.target).isChildOfElement('#'+container) == false) {
					$('.hintDiv').fadeOut("4000");
				} 
				
				else if ($(event.target).hasClass('hintImg')) {

					var imgOffset = $(event.target).offset();

					$("#" + $(event.target).attr("rel")).css("top", (imgOffset.top - 20) + "px");
	
					if ($("#" + $(event.target).attr("rel")).hasClass("alignLeft")) {
						$("#" + $(event.target).attr("rel")).css("left", (imgOffset.left - ($("#" + $(event.target).attr("rel")).outerWidth() / 2) - 20) + "px");
						
					} else {
						$("#" + $(event.target).attr("rel")).css("left", (imgOffset.left - 20) + "px");
					}

					if ($("#" + $(event.target).attr("rel")).css("display") != "block") {

						$('.hintDiv[id!="' + $(event.target).attr("rel") + '"]').fadeOut("4000");
						$("#" + $(event.target).attr("rel")).fadeIn("2000");

					}
					
				}

		});
		
	}
	
	
	
	
	
	
	

		//accordion 
	
	$(function () {
			
			$('ul.drawers').accordion({
			
			// the drawer handle
			header: 'h5.drawer-handle',
			active: '.open',
			alwaysOpen: false,
			
			// our selected class
			selectedClass: 'open',
			fillSpace: false,
			autoHeight: false,
			// match the Apple slide out effect
			event: 'click'  });
			
		});


		$(function () {
			
			$('ul.drawers-child').accordion({
			
			// the drawer handle
			header: 'h5.drawer-child-handle',
			active: '.open',
			alwaysOpen: false,
			
			// our selected class
			selectedClass: 'open',
			fillSpace: false,
			autoHeight: false,
			// match the Apple slide out effect
			event: 'click'  });
			
		});	
		
		
		
		$(function () {
			
			$('ul.downloadDrawer').accordion({
			
			// the drawer handle
			header: 'a.drawer-handle',
			active: '.open',
			alwaysOpen: false,
			
			// our selected class
			selectedClass: 'open',
			fillSpace: false,
			autoHeight: false,
			// match the Apple slide out effect
			event: 'click'  });
			
		});


$(document).ready( function (){
	
	$(".zoom").click( function(){
		
		
		var img = $(this).parent().find('div.imgholder');
		var imgzoom = $(this).parent().find('div.imgholder_zoom');

		if($(img).css('display') == 'block'){
			$(img).css('display', 'none');
			$(imgzoom).css('display', 'block');
			$(this).html('Zoom -');
		}else{
			$(img).css('display', 'block');
			$(imgzoom).css('display', 'none');
			$(this).html('Zoom +');
		}

	});

	$(".imgholder_zoom").mousemove( function(e){
		//position of the mouse inside the element
		var x = e.pageX - $(this).position().left;
		var y = e.pageY - $(this).position().top;

		//percentage of the mouse to the element
		var pw = (x / $(this).width()) * 100;
		var ph = (y / $(this).height()) * 100;

		//width and heigh of the image
		var img = $(this).find('img');
		var iw = $(img).width();
		var ih = $(img).height();

		//get the overflow of the image
		var ow = iw - $(this).width();
		var oh = ih - $(this).height();

		var movew = (ow / 100) * pw;
		var moveh = (oh / 100) * ph;

		$(img).css({
			'left' : '-'+Math.floor(movew)+'px',
			'top'  : '-'+Math.floor(moveh)+'px',
			position : 'absolute'
		});
	});

});
	

function dHoverFunc(value, date, inst) {
    if(value == null) return;
}


function markDates()
{
	$('.cdateinput').each(function(key){


		if ($('#cd_'+$(this).val()).hasClass('is_marked')) {
			$('#cd_'+$(this).val()).addClass('multiple_events');
			$('#cd_'+$(this).val()).attr('rel', $(this).val());
		}
		else 
		{
                        var Cat = $('input[name="cevent_cat_'+$(this).attr('rel')+'"]').val();
                        var Total = $('input[name="cevent_total_'+$(this).attr('rel')+'"]').val();
                        var Available = $('input[name="cevent_available_'+$(this).attr('rel')+'"]').val();
                        // Parse date
                        var pDate = Date.parse($(this).val().replace(/-/g, '/'));
			if (Cat == "6" && pDate > ((new Date().getTime()) - (1000*60*60*24))) {
				if (Available > 0) {
					$('#cd_'+$(this).val()).addClass('darkGreenDay');
				} else {
					$('#cd_'+$(this).val()).addClass('blackDay');
				}
			
			} else if (Cat == "7" && pDate > ((new Date().getTime()) - (1000*60*60*24))) {
				if (Available > 0) {
					$('#cd_'+$(this).val()).addClass('greenDay');
				} else {
					$('#cd_'+$(this).val()).addClass('blackDay');
				}

			}
			else {
				$('#cd_'+$(this).val()).addClass('blackDay');
			}
			var xOffset = 10; var yOffset = 10;
			$('#cd_'+$(this).val()).addClass('is_marked');
			$('#cd_'+$(this).val()).attr('rel', $(this).attr('rel'));
                        /* On Hover Tooltip */
                        if(Cat != "5") {
                            $('#cd_'+$(this).val()).attr('rev', "Places Booked: " + (Total - Available) + "<br />Places Available: " + Available);
                            $('#cd_'+$(this).val()).hover(function(e) {
                                $("body").append("<p id='tooltip'>"+ $(this).attr('rev') +"</p>");
                                $("#tooltip")
                                    .css("top", (e.pageY - xOffset) + "px")
                                    .css("left", (e.pageX + yOffset) + "px")
                                    .fadeIn("fast");
                            }, function() {
                                $('#tooltip').remove();
                            });
                            $('#cd_'+$(this).val()).mousemove(function(e) {
                                $("#tooltip")
                                    .css("top", (e.pageY - xOffset) + "px")
                                    .css("left", (e.pageX + yOffset) + "px");
                            });
                        }

		}
		
	});
}
	
function clickCalendar(datestr)
{
	if ($('#cd_'+datestr).hasClass('is_marked')
	&& $('#cd_'+datestr).hasClass('multiple_events')
	) {
		window.location.href=$('input[name="domainUrl"]').val() + $('input[name="pageUrl"]').val() + '?seldate='+datestr;
	}
	else if ($('#cd_'+datestr).hasClass('is_marked')
	&& ($('#cd_'+datestr).hasClass('multiple_events') == false)
	) 
	{
		window.location.href=$('input[name="domainUrl"]').val() + 'events/id-' + $('#cd_'+datestr).attr('rel');
	}
}




function isValidEmail(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

