// default.js

$(function(){
	
	$(document).pngFix();
	
	//
	$('.screen>a').cycle({ 
		fx:    'fade', 
		speed:	1000,
		timeout: 10000,
		pause:	1,
		pauseOnPagerHover: 1,
		pager: '.thumbnails',
		pagerAnchorBuilder: function(idx, slide) { 
				var imageLocation	= $(slide).attr('meta');
				//var domainName		= document.domain;
				
				//imageLocation = imageLocation.substring(domainName.length + 7);

                return '<a href="#"><img src="/image.php?action=autoCrop&m_w=56&m_h=47&q=80&p=top_center&path=' + imageLocation + '" /></a>';
        },
		updateActivePagerLink: function(container, slide) {
			$(container+'>a').removeClass('sel');
			$(container+'>a:eq('+slide+')').addClass('sel');	
		},
		cleartype:  true,
    	cleartypeNoBg:  true

	});
	
	//
	$('#floatbox').cycle({ 
		fx:    'fade', 
		speed:	1000,
		timeout: 10000,
		pause:	1,
		pauseOnPagerHover: 1,
		pager: '.buttons',
		pagerAnchorBuilder: function(idx, slide) { 
                return '<li><a href="#">&nbsp;</a></li>';
        },
		updateActivePagerLink: function(container, slide) {
			$(container+'>li>a').removeClass('sel');
			$(container+'>li:eq('+slide+')>a').addClass('sel');	
		},
		cleartype:  true,
    	cleartypeNoBg:  true

	});
	
	//
	$('#clients,#news').cycle({ 
		fx:    'scrollHorz', 
		speed:	1000,
		timeout: 10000,
		pause:	1,
		pauseOnPagerHover: 1,
		pager: '.buttons',
		pagerAnchorBuilder: function(idx, slide) { 
                return '<li><a href="#">&nbsp;</a></li>';
        },
		updateActivePagerLink: function(container, slide) {
			$(container+'>li>a').removeClass('sel');
			$(container+'>li:eq('+slide+')>a').addClass('sel');	
		},
		cleartype:  true,
    	cleartypeNoBg:  true

	});
	
	// contact
	$('#userForm').ajaxForm({
        beforeSubmit:  	function(formData, form, options){
							$('#error').slideUp();
							return true;
						}, 
        success:       	function(data, status, xhr, form){
							if(data.success == true){
								$('#userForm').slideUp('slow', function(){ $('#thankYou').slideDown(); });
							} else {
								$('#error').slideDown();
							}
						},
		url:			'/ajax.php',
		type:			'post',
		dataType:		'json'
	});
	
	$('#map').each(function(){
		if (GBrowserIsCompatible()) {
			
			$(this).empty();
			
			mapA = new GMap2(this);
			mapA.addControl(new GSmallMapControl());
			mapA.addControl(new GMapTypeControl());

        	geocoder = new GClientGeocoder();
			
													
			var building = 'Ingenious, Inc.';
			var sTaddress = '742 Washington St., Suite 201, Buffalo, NY 14203';
			var sFaddress = '742 Washington St.<br>Suite 201<br>Buffalo, NY 14203';
			var sTdirections = 'http://www.google.com/maps?f=d&hl=en&saddr=' + '' + '&daddr=' + sTaddress;
			var sFdirections = 'http://www.google.com/maps?f=d&hl=en&saddr=' + sTaddress + '&daddr=';

			var sTinfo = '<div style="text-align: left;">' + building + '<br>' + sFaddress + '<br><br>Get directions: <a href="' + sTdirections + '">To here</a> - <a href="' + sFdirections + '">From here</a><br><br></div>';
			//$(this).empty();
			
			//
			var homeIcon = new GIcon(G_DEFAULT_ICON);
			homeIcon.image = "/images/layout/marker.png";
							
			//
			markerOptions = { icon:homeIcon };
			
			point = new GLatLng(42.893925, -78.87069);
			mapA.setCenter(point, 17);
			
			var marker = new GMarker(point, markerOptions);
			mapA.addOverlay(marker);
		  
			GEvent.addListener(marker, "click", function() {
				marker.openInfoWindowHtml(sTinfo);
			});
			
			var polygon = new GPolygon([
			  new GLatLng(42.894044,-78.870445),
			  new GLatLng(42.893856,-78.869461),
			  new GLatLng(42.893042,-78.869713),
			  new GLatLng(42.893120,-78.870201),
			  new GLatLng(42.893560,-78.870070),
			  new GLatLng(42.893650,-78.870570),
			  new GLatLng(42.894044,-78.870445),
			], "#2aa92a", 2, 1, "#2aa92a", 0.2);
			mapA.addOverlay(polygon);
			
			//
			var parkingIcon = new GIcon(G_DEFAULT_ICON);
			parkingIcon.image = "http://chart.apis.google.com/chart?chst=d_map_pin_icon&chld=parking|2aa92a";
							
			//
			markerOptions2 = { icon:parkingIcon };
			
			point2 = new GLatLng(42.893744, -78.870008);
			
			var marker2 = new GMarker(point2, markerOptions2);
			mapA.addOverlay(marker2);
		
		}	
	});
	
	// event tracker for outgoing links/file downloads
	$('a').each(function(){
		var path;
		
		if(path = $(this).attr('href')){
			var outgoing 	= /^(http|https)/i;
			var ext 		= /[^/].(?:doc|eps|jpg|jpeg|png|svg|xls|ppt|pdf|xls|zip|txt|vsd|vxd|js|css|rar|exe|wma|mov|avi|wmv|mp3|mp4)/i;
			
			if (path.match(outgoing) && !path.match(document.domain) ) {
				$(this).click(function(){
					
					// new ga code
					_gaq.push(['_trackEvent', 'Link', 'Outgoing', $(this).attr('href')]);
				});
			} else if(path.match(ext)){
				$(this).click(function(){
					
					// new ga code
					_gaq.push(['_trackEvent', 'File', 'Download', $(this).attr('href')]);
				});	
			}
		}
	});
	
	$('.hide').hide();
	
});
