/*
 * Google Tracking Code
 *
 */
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-19030695-1']);
_gaq.push(['_trackPageview']);

(function() {
	var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
	ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
	var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

$(document).ready(function() {
	/*
	 * Adds randomized quotes to all pages
	 *
	 */
	$.get('/php/compliments.php', function(data) {
		$('#test_bar_links').html(data).cycle({
			fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
			random:1,
			randomizeEffects: true,
			timeout:3000
		});
	});
	/*
	 * Comment & Request Bid form Changes
	 *
	 */
	$('#reason').change(function(e){
		switch(this.value){
			case 'bid':
				$('#bidfields').show();
				$('#bidfields input, #bidfields textarea').attr('disabled','');
			break;
			case 'general':
				$('#bidfields').hide();
				$('#bidfields input, #bidfields textarea').attr('disabled',true);
			break;
		}
	});
	
	/*
	 * Image Galleries
	 *
	 */
	var overlayApi = $("#gallery-overlay").overlay({
		mask: {
			color: '#000000',
			opacity: 0.5
		},
		top: 20,
		fixed: false
	}).data("overlay");
	var scrollApi = $('#gallery-overlay .scrollable').scrollable({
		prevPage:'.prev',
		nextPage:'.next'
	}).data("scrollable");
	$('#gallery-thumbs img, #gallery-thumbs .album-name').click(function(event) {
		$('#gallery-overlay .fullsize').css('background-image', '');
		$('#gallery-overlay .scrollable .items').empty();
		$(this).parents('li.album').find('img').each(function() {
			event.preventDefault();
			var $elm = $(this);
			//var fullSizePath = $elm.attr('href');
			var thumbPath = $elm.attr('src');
			var fullSizePath = thumbPath.replace('thumbs','gallery');
			var desc = $elm.attr('alt');
			$('<div class="item" rel="'+fullSizePath+'" title="'+desc+'"/>').css('background-image', 'url(' + thumbPath + ')')
				.appendTo('#gallery-overlay .scrollable .items');
		});
		scrollApi.getItemWrap().css('left', '0');
		scrollApi.begin().getItems().filter(':first').click();
		overlayApi.load();
	});
	$('#gallery-overlay .scrollable .items .item').live('click', function(event) {
		var $elm = $(this);
		var $wrap = $('#gallery-overlay .fullsize');
		var path = $elm.attr('rel');
		var img = new Image();
		$wrap.css('background-image', '');
		img.onload = function() {
			$wrap.css('background-image', 'url(' + path + ')');
		};
		img.src = path;
		$('#gallery-overlay > .description').text($elm.attr('title'));
	});
	$('.album :nth-child(2)').addClass('first');
});
