// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

$(function() {
	$('#email-form-container input').placeholder();

	$('#view-more-projects').click(function(event) {
		event.preventDefault();

		jQuery.get('/portfolio/thumbs_list', function(data) {
			$('#slider-content').html(data);
		});
	});
	
	if ($('#slideshow-photos').length != 0) {
		$('#slideshow-photos').cycle({
			fx: 'scrollLeft',
			speed: 'fast',
			timeout: 0,
			next: '#pager-next',
			pager: '#slideshow-nav',
			pagerAnchorBuilder: function(idx, slide) {
				return '<li><a href="#">' + idx + '</a></li>';
			},
			before: function() {
				alt = $(this).find('img').first().attr('alt')
				$('#slideshow-caption').text(alt);
			}
		});
	}
	
	initTooltips();
});

function initTooltips() {
	$('a.tooltip').each(function() {
		$(this).qtip({
			content: $(this).attr('rel'),
			position: {
				target: 'mouse',
				corner: {
					target: 'topRight',									
					tooltip: 'bottomLeft'
				}
			},
			style: {
				width: 252,
				border: 0
			},
			show: {
				when: { event: 'mouseover' },
				effect: { length: 0 }
			},
			hide: {
				when: { event: 'mouseout' },
				effect: { length: 100 }
			}
		});
	});	
}

function sketchbookScroll(interval, sketchbook_page) {
	$('#flickr-thumbs-list').css('opacity', 0.3);
	
	jQuery.get('/sketchbook/scroll?interval=' + interval + '&page=' + sketchbook_page, function(data) { 
		$('#thumbs').html(data);
	}, function() {
		$('#flickr-thumbs-list').css('opacity', 1);
	});
}

/* START Slider */
$(function() {
	$('#industry-slider-link, #thumbs-slider-link').click(function() {
		clicked = $(this);
		
		if ($('#popup-nav').hasClass('open')) {
			if (clicked.attr('id') == 'industry-slider-link' && $('#slider #horizontal_carousel.open').length != 0) {
				$('#horizontal_carousel').removeClass('open');
				$('#slider-client-list').addClass('open');
			}
			else if (clicked.attr('id') == 'thumbs-slider-link' && $('#slider #slider-client-list.open').length != 0) {
				$('#slider-client-list').removeClass('open');
				$('#horizontal_carousel').addClass('open');
				initCarousel();
			}
			else
				slideClosed();
		}
		else {
			if (clicked.attr('id') == $('#industry-slider-link').attr('id')) {
				$('#horizontal_carousel').removeClass('open');
				$('#slider-client-list').addClass('open');
				slideOpen();
			}

			if (clicked.attr('id') == $('#thumbs-slider-link').attr('id')) {
				$('#slider-client-list').removeClass('open');
				$('#horizontal_carousel').addClass('open');
				slideOpen();
				initCarousel();
			}
		}
		
		function slideOpen() {
			$('#slider').slideDown('fast');
			$('#popup-nav').addClass('open');
		}
		
		function slideClosed() {
			$('#slider').slideUp('fast');
			$('#popup-nav').removeClass('open');
		}
	});
});