// JavaScript Document

function showSignup() {
	var url = "sign_up.php?keepThis=true&amp;TB_iframe=true&amp;height=600&amp;width=459&amp;modal=true";
	tb_show(null, url);
}

function unlock() {
	$('#imgSurround').unblock();
}

function autoSlideTo(page) {
	page = parseInt(page);
	
	//reset if too far
	if (page > $('#maxSlides').val()) page = 1;
	
	//animate
	var topX = (page * 940) - 940;
	$('#holder').animate({
		left: -topX
	}, 1000, 'swing');
	
	var next = page + 1;
	
	//recall
	setTimeout("autoSlideTo(" + next + ")", 4000);
}

$(document).ready(function(){
	$('.ro img').hover( function() {
		this.src = this.src.replace("_off","_on");
	}, function() {
	 	this.src = this.src.replace("_on","_off");
	});
	
	$('.hide').hide();
	$('.dropdown').click( function() {
		var panel = $(this).attr('rel');
		var thisID = $(this).attr('id');
		
		if ($('#' + panel).hasClass('dropped')) {
			$('#' + panel).slideUp('slow');
			$('#' + panel).removeClass('dropped');
			$('#' + thisID).removeClass('dropped');
			$.cookie(panel, panel);
		} else {
			$('#' + panel).slideDown('slow');
			$('#' + panel).addClass('dropped');
			$('#' + thisID).addClass('dropped');
			$.cookie(panel, null);
		}
		return false;
	});
	
	$('.swapImg').click(function() {
		$('#imgSurround').block({ 
			message: '<img src="/images/ajax-loader.gif">', 
			css: 	{ 	border: 'none',
						backgroundColor:'none'
					} 
		});						 
		var newImg = $(this).attr('href');
		var hqImg = newImg.replace("_large", "_hq");
		
		$('#mainImg').attr("src", newImg);
		$('#imgSurround a').attr("href", hqImg);
		
		$('#imgSurround').onImagesLoad({
			selectorCallback: unlock						   
		});
		
		return false;								 
	});
	
	$('.hide').hide();
	$('.controls a').click( function() {
		var page = $(this).attr('rel');
		page = parseInt(page);
		var topX = (page * 940) - 940;
		var next = page + 1;
		var prev = page - 1;
		
		$('#holder').animate({
			left: -topX
		}, 1000, 'swing');
		
		$('.next a').attr('rel', next);
		$('.prev a').attr('rel', prev);
		
		if (page == 1) $('.prev').hide();
		else $('.prev').show();
		
		if (page == $('#maxSlides').val()) $('.next').hide();
		else if ($('#maxSlides').val() != 1) $('.next').show();
		
		return false
	});

	
	var animateSub = new Array();
	
	/*$('.submenu').mouseenter(function(){
		var size = $(this).attr('rel');
		var liID = $(this).attr('id');
		animateSub[liID] = true;
		$(this).css("z-index", 100000);
		size = parseInt(size);							  
		$('.link',this).animate({
			width: size
		}, 200, 'swing', function() {
			// Animation complete.
			if (animateSub[liID]) $('.' + liID).slideDown(200);
		});
	}).mouseleave(function(){
		var size = 140;
		var liID = $(this).attr('id');
		animateSub[liID] = false;
		$(this).css("z-index", 1000);
		
		$('.' + liID).slideUp(200, function() {
			$('#' + liID + ' .link').animate({
				width: size
			}, 200, 'swing');
		});
	});*/
	
	$('.link').click(function(){
		var size = $(this).attr('rel');
		var liID = $(this).attr('id');
		
		if ($(this).width() == size) {
			animateSub[liID] = false;
			$(this).css("z-index", 1000);
			size = parseInt(140);
			
			$('.' + liID).slideUp(200, function() {
				$('#' + liID).animate({
					width: size
				}, 200, 'swing');
			});
		
		} else {
			animateSub[liID] = true;
			$(this).css("z-index", 100000);
			size = parseInt(size);							  
			$(this).animate({
				width: size
			}, 200, 'swing', function() {
				// Animation complete.
				if (animateSub[liID]) $('.' + liID).slideDown(200);
			});
		}
				
		return false;
	});
	
	$("a[rel=gallery]").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-over">(' + (currentIndex + 1) + ' / ' + currentArray.length + ')' + (title.length ? ' &nbsp; ' + title : '') + '</span>';
		}
	});
	
		
	$('.top').click( function() {
		$.scrollTo( this.hash , 1000, {easing:'swing'});
		return false
	});
	
	$('.qtip').qtip({
		show: 'mouseover',
		hide: 'mouseout',
		position: {
			target: 'mouse',
			corner: 'leftMiddle',
			adjust: { x: 10, y: 0 }
		},
		style: {
			border: {
				width: 1,
				radius: 5,
				color: '#8dc63f'
			},
			background: '#FFF',
			color: '#333',
			padding: 8, 
			width: { max: 200 },
			tip: true // Give it a speech bubble tip with automatic corner detection
			//name: 'dark' 
		}
	});
	
	/*$('.keywords').focus(function() {
		if ($(this).val() == "Search //") {
			$(this).val('');;
		}
	});
	
	$('.keywords').blur(function() {
		if ($(this).val() == "") {
			$(this).val('Search //');
		}
	});*/
	
	$(".bubble").fancybox({
		'width'				: 300,
		'height'			: 350,
        'autoScale'     	: false,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});
	
	$(".enquiry").fancybox({
		'width'				: 400,
		'height'			: 350,
        'autoScale'     	: false,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});
	
});
