jQuery.noConflict(); //Silverstripe Prototype Form validation Run-ins
jQuery(document).ready(function($) {

if($('a.img').attr('name')){
$('a.img').each(function(){ $(this).data('info',$(this).attr('href')).attr('href',$(this).attr('name')); });
}
if($('a#bio-l').attr('name')){
var loc = $('a#bio-l').attr('name');
$('a#bio-l').attr('href',loc);
}

if($('body.home #content').length){
/* -- Sets the Location and Shows the info div. -- 
$('.main-image .panel').hover(function(){ $('.panel:visible .info').fadeIn('slow');$(this).css('cursor','pointer');$(this).click(function(){window.location = $('.main-image .info:visible a').attr('href');});
},function(){
$('.fade:visible').fadeOut('fast');
});
*/
$('.main-image').innerfade({
	animationtype: 'fade', //options : slide | fade
	type:'random',
	speed:'slow',
	timeout:3500,
	containerheight:'300'
});

}

if($('#text img#swap').length){

$('body').append('<div class="pp_pic_holder dark_rounded" id="loader" style="left: 48%; top: 500px;display:none;"><div class="pp_top"><div class="pp_left"></div><div class="pp_middle"></div><div class="pp_right"></div></div><div class="pp_content"><div class="pp_loaderIcon" style="display:block"></div></div><div class="pp_bottom"><div class="pp_left"></div><div class="pp_middle"></div><div class="pp_right"></div></div></div>');

$('.list .art a').hover( //When a link is hovered...
function(){
if($(this).attr('name')){//If there is a title (waay too much error checking -- but. It's good)
hideOvr();//Hide overlay 2
$('#text img#swap').attr('src',$(this).attr('name')).attr('go',$(this).attr('href')).addClass('lf'); //Swap the Image
setTimeout("showLoader()", 250); //Show loading if img doesn't quickly load.

// (might change to overlay fade... Can't decide, then I'd be pushing stacks...)
}
else {
var loc = $(this).attr('href');
$('#ovr').html('<a href="'+loc+'">Image for '+$(this).html()+' cannot be found.</a>').show();
$('#text img#swap').attr('go',loc);
}
},function(){});

$('#text img#swap').load(function(){
$(this).removeClass('lf');
$('#loader').fadeOut(450);
});

$('#text img#swap').click(function(){
	if($(this).attr('go')){ //If Go!
		window.location = $(this).attr('go'); //GO!
	}
});

$('#ovr').click(
function(){
hideOvr();
}); //When the overlay is clicked, hide it.

}

$('#bio-quote a').attr('rel','fb');

$('#bio-quote').click(function(){
	$.facebox($('#bio-main').html());
});

/*$('a#legal-link').click(function(){
			$.facebox('Loading');
			$('#facebox .content').load('/legal #text');
			return false;});*/
$('a#legal-link').attr('href','/legal/ajax').attr('rel','fb');

$('a[rel*="fb"]').facebox();

/*click(function(){
	//$.get($(this).attr('href'),(function(data){$.facebox(out.filter('#text').html());}));
	$(this).facebox();
	return false;
});*/

/*$('#bio-quote a').click(function(){
	$(this).slideUp('slow');
	var loc = $(this).attr('href');
	$('#bio-main').show('slow');
	return false;
});*/



function hideOvr() {
if ($('#ovr:visible').length) {
$('#ovr').fadeOut('slow');
$('#text img#swap').css('cursor','pointer'); //Adds 'link' effect w/ javascript
}

}

$("a[rel^='pop']").prettyPhoto({
				animationSpeed: 'normal', /* fast/slow/normal */
				padding: 40, /* padding for each side of the picture */
				opacity: 0.35, /* Value betwee 0 and 1 */
				showTitle: true, /* true/false */
				allowresize: true, /* true/false */
				counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
				theme: 'dark_rounded', /* light_rounded / dark_rounded / light_square / dark_square */
				callback: (function(){setTimeout("DragHandler.attach(document.getElementById('fullResImage')); bindClick('#fullResImage');",800);})
			});




$('#nav-list .current, #nav-list .section').addClass('selectedLava');
/* -- Lava Lamp Depreciated -- >
$('#nav-list').lavaLamp({
	fx: 'easeInExpo',
	speed: 200,
	startItem: 1
});
*/
$('body').append('<div id="click" style="display:none;"><ul ><li><a href="/legal">Image &copy; Gallery 1401</a></li><li><a href="/contact-us">Interested? Contact Us</a><li class="img"></li></ul></div>');

bindClick('img, a:has(img)');



$(document).click(function(){$('body div#click').slideUp('slow');});

$('img, a:has(img)').each(function(el){

DragHandler.attach(this);

});

});

function bindClick(sel2){
if(!sel2){sel2 = 'img, a:has(img)';}
jQuery(sel2).bind("contextmenu",function(e){

			var $add = jQuery('body div#click li.img');
			var $click = jQuery('body div#click');
			
			if (jQuery(this).parent("a")){
			var $link = jQuery(this).parent("a");
			if ($link.data('info')){
			$add.html($img.data('info'));
			}
			else if ($link.attr('title')){
			$add.html('<a href="'+$link.attr('href')+'>"'+$link.attr('title')+'</a>');
			}
			else if ($link.attr('href')){
			$add.html('<a href="'+$link.attr('href')+'">View Image</a>');
			}
			}
			else if (jQuery(this).attr('go')){
				if (jQuery(this).attr('alt')){ var text = jQuery(this).attr('alt'); } else { var text = 'View Image'; }
			$add.html('<a href="'+jQuery(this).attr('go')+'">'+text+'</a>');
			}
			else if (jQuery(this).attr('alt')){
			$add.html(jQuery(this).attr('alt'));
			}
			else {
			$add.html('');
			}
			
			$click.slideDown('slow').css({
				top:e.pageY+"px",
				left:e.pageX+"px",
				position:"absolute",
				opacity: 0.8,
				zIndex: 2000
			});
			
			return false;

});
}

function SwitchColor() {
 var keywords = ['red','green', 'blue','sky','yellow'];
 var keyword = keywords[Math.floor(Math.random()*keywords.length)];
 jQuery('body').removeClass(keywords.join(' '));
 jQuery('body').addClass(keyword);
 setTimeout('SwitchColor()',2000);
}
 function menuC(){
jQuery.facebox(((jQuery('#top').width() - jQuery('ul#nav-list').width()) / 2));
}
 function showLoader(){
 if (jQuery('#text img#swap').hasClass('lf'))
 {
 jQuery('#loader').show();
 }
 }

