jQuery(function(){

// target_blank
$('a[href^="http://"]')
  .attr({
    target: "_blank", 
    title: "This link will open in a new window"
  });

});


// form
$(document).ready(function(){
  $('.fadein a:gt(0)').hide();
  setInterval(function(){$('.fadein a:first-child').fadeOut(1000).next('a').fadeIn(600).end().appendTo('.fadein');}, 8000);
});


jQuery(function() { 
	var options = { 
		target: '#alert'
	}; 
	$('#contactForm').ajaxForm(options);
}); 
	
$.fn.clearForm = function() {
	return this.each(function() {
		var type = this.type, tag = this.tagName.toLowerCase();
		if (tag == 'form')
			return $(':input',this).clearForm();
		if (type == 'text' || type == 'password' || tag == 'textarea')
			this.value = '';
		else if (type == 'checkbox' || type == 'radio')
			this.checked = false;
		else if (tag == 'select')
			this.selectedIndex = -1;
	});
};	





// Flickr API js
$(document).ready(function () {  
Galleria.loadTheme('js/themes/markmans/galleria.markmans.js');

var flickr_api_key = 'bdc8afed3dd6ecba073396fb833a2e1a'; // Flickr API Key
var flickr_user_id = '51006813@N05'; //Flickr User ID

// intiialize flickr plugin
var flickr = new Galleria.Flickr(flickr_api_key);

$('.light-box').click(function(){
    var $this = $(this);
    var gTags = $this.attr('href');

    $.fancybox({
        'padding': 0,
        'autoScale': false,
        'autoDimensions': false,
        'width': 800,
        'height': 650,
        'type': 'inline',
        'overlayOpacity': 0.5,
        'overlayColor': '#000',
        'onStart':  flickr.search({
            'user_id':flickr_user_id,
            'tags':gTags.substring(1, gTags.length)
        }, {
            max: 80,
            size: 'medium',
            sort: 'date-posted-desc'
        }, function(data) {
            $('#fancybox-inner').galleria({
                data_source: data,
                carousel_steps: 7,
                hide_dock: false,
                image_crop: false,
                transition: 'fade'
            });
        })
        
    });       
    return false;
});
});


// smooth scroll
$(function(){
    $('a[href*=#]').click(function() {
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') 
        && location.hostname == this.hostname) {
            var $target = $(this.hash);
            $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
            if ($target.length) {
                var targetOffset = $target.offset().top;
                $('html,body').animate({scrollTop: targetOffset}, 900);
                return false;
            }
        }
    });
});


// fixed scroll nav
$(document).ready(function () {  
  var top = $('#asideWrap').offset().top - parseFloat($('#asideWrap').css('marginTop').replace(/auto/, 0));
  $(window).scroll(function (event) {
    // what the y position of the scroll is
    var y = $(this).scrollTop();
  
    // whether that's below the form
    if (y >= top) {
      // if so, ad the fixed class
      $('#asideWrap').addClass('fixed');
    } else {
      // otherwise remove it
      $('#asideWrap').removeClass('fixed');
    }
  });
});



