$(document).ready(function() {
// Remove Gutter on Portfolio
$("ul#gallery li:nth-child(3n)").removeClass('gutter');

// FancyBox
$("a[rel=minis]").fancybox({
			'transitionIn'		: 'elastic',
			'transitionOut'		: 'fade',
			'titlePosition' 	: 'over',
			'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
				return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
		}
	});

// Special
// the list of domains to check and an array which will store hits
var domains = ['wemaonline.ca', 'searchrevolutionmarketing.com', 'mediadog.ca', 'webcandy.ca', 'olympiatrust.com'];
var visited = [];
//for every domain...
$.each(domains,function() {
//inject a link into page
var a = $('<a></a>').attr({href: 'http://' + this, 'class': 'checkme'}).appendTo('#special');
  //check the color of the link
  if($(a).css('color') == '#ff0000' || $(a).css('color') == 'rgb(255, 0, 0)') { //either format of color
    $(a).addClass('highlight');
    visited.push(this);
  }
  //remove from the page -- no longer need the links
  a.remove();
});
if(visited.length) {
function oc(a)
{
  var o = {};
  for(var i=0;i<a.length;i++)
  {
    o[a[i]]='';
  }
  return o;
}

// Now give a custom message based on the history
if( ('wemaonline.ca' in oc(visited)) ) { $('#outreach').html('<p class="emphasize">Contact us to find out more about our 20% discount for WEMA Members.</p>'); }

else if( ('mediadog.ca' in oc(visited)) || ('webcandy.ca' in oc(visited)) ) { $('#outreach').html('<p class="emphasize">Been shopping around?  You don\'t have to break the bank to have an awesome site.</p>'); }

else if( ('olympiatrust.com' in oc(visited)) || ('olympiatrust.com' in oc(visited)) ) { $('#outreach').html('<p>We\'ve helped take Olympia Financial Group into the internet age, and helped many other profitable businesses. We can help you too!</p>'); }

}


// AJAX For Contact Form
	$("#ajax-contact").submit(function() {
		var dataString = $(this).serialize();
		$('#contact-form').html('<img src="http://www.undergalaxie.com/images/ajax-loader.gif" />').hide().show('slow');
		
		$.ajax({
			type: "POST",
			url: "http://www.undergalaxie.com/message.php",
			data: dataString,
			success: function() {
				$('#contact-form').html("<h2>Thank you for your message.</h2><p>We'll be in touch shortly.</p>").hide().show('slow');
			}
		});
		return false;
	});
	
// NIVO Slider
	$('#slider').nivoSlider({
			effect:'fade', // Specify sets like: 'fold,fade,sliceDown'
			animSpeed:1000, // Slide transition speed
			pauseTime:12000, // How long each slide will show
			startSlide:0, // Set starting Slide (0 index)
			directionNav:false, // Next & Prev navigation
			controlNav:false, // 1,2,3... navigation
      pauseOnHover: false, // Stop animation while hovering
});
		
// Small nudge for links with the .nudge class
	$('a.nudge').hover(function() { //mouse in
			$(this).animate({ paddingLeft: '10px' }, 400);
		}, function() { //mouse out
			$(this).animate({ paddingLeft: 0 }, 400);
		});

// Clears out input boxes that have values onclick
	$(".filled").focus(function() {
		if( this.value == this.defaultValue ) {
			this.value = "";
		}
		}).blur(function() {
		if( !this.value.length ) {
			this.value = this.defaultValue;
		}
		});
	
// Sends rel="external" to a new tab/window
	$('a[rel="external"]').click( function() {
			window.open( $(this).attr('href') );
			return false;
			});  

// Hover effects for image rollovers
  if ($.browser.msie && $.browser.version < 7) return;  
  $('#navigation li, #language li')
    .removeClass('highlight')
    .find('a')
    .append('<span class="hover" />').each(function () {
      var $span = $('> span.hover', this).css('opacity', 0);
      $(this).hover(function () {
        $span.stop().fadeTo(500, 1);
      }, function () {
        $span.stop().fadeTo(1000, 0);
      });
    });

});
