
$(document).ready(function(){

	$('#streetbox').hide();

	$('#artworkgallery a').fadeTo( 0, 0.2 );
	$('#artworkgallery .loading').stop().fadeTo( 100, 1 );
	$('#artworkgallery a').hover( 
		function(){ $(this).find('img').stop().fadeTo(400, 1); }, 
		function(){ $(this).find('img').stop().fadeTo(300, .5); });


//-------------- Begin artwork gallery
	$('#artworkgallery a').lightBox(); 
//-------------- end artwork gallery

//-------------- Begin artwork gallery
	$('.eventArt').lightBox(); 
//-------------- end artwork gallery

//-------------- BEGIN prettyPhoto for videos
	$("a[rel^='prettyPhoto']").prettyPhoto({
		theme: 'dark_rounded',
		default_width:854,
		default_height:511		
	});
//-------------- END prettyPhoto for videos


	Galleria.loadTheme('js/themes/classic/galleria.classic.js');

	$('#maingallery').galleria({
		height: 433,
		transition: 'flash'
	});	
        
	//slideshow transition type - all transition types included with jquery cycle will work
	var transition = 'fade';
	//turn the pan's negative if you'd like to transition the other way
	var pan_x = -30;
	var pan_y = -150;
	//# of seconds between fades
	var fadeDisplayTime = 7 
	//# of seconds it takes to pan on the x/y axis
	var pan_x_time = 7
	var pan_y_time = 7

	$("#menu a, .friendlink a, #radiolink").blend();

 	$(".tweet").tweet({
            username: "abandcalledmouth",
		query: "from%3Abandcalledmouth",            
		avatar_size: 64,
		count: 5,
		sloading_text: "loading tweets..."
        });
	
//-------------- begin cycle plugin with panning effect
	$.fn.getXdir = function (){
		return ( $(this).hasClass("panLeft") ) ? 1 : -1;
	}	
	$.fn.getYdir = function (){
		return ( $(this).hasClass("panDown") ) ? 1 : -1;
	}	
	$.fn.initSlidePos = function ( x, y ){
		//Set x
		if( $(this).getXdir() < 0 ) {			
			$(this).css({ left: 0 });
		} else {
			$(this).css({ left: (x * $(this).getXdir() ) });
		}
		
		//Set y
		if( $(this).getYdir() < 0 ) {	
			$(this).css({ top: 0 });
		}else{
			$(this).css({ top: ( y * $(this).getYdir() ) });
		}
			
		return $(this);
	}

	var firstTime = true;
	
	$('#slides').cycle({
		fx: transition,
		timeout: (fadeDisplayTime * 1000),
		before: function(currSlideElement, nextSlideElement, options, forwardFlag){
    			var $obj = $(this);
    		
    			if(firstTime){
    				$obj.initSlidePos( pan_x, pan_y);
    				firstTime = false;
    			}    		
    		
    			setTimeout( function(){
    				$obj.initSlidePos( pan_x, pan_y );
    			}, 50);
	    		},
		after: function(currSlideElement, nextSlideElement, options, forwardFlag){
    			var $obj = $(this);
    		
    			if( $obj.getXdir() < 0 ) {    			
    				$obj.animate({ left: pan_x  },{ duration: (1000 * pan_x_time), queue:true });
    			} else {    			
    				$obj.animate({ left: "0" },{ duration:(1000 * pan_x_time), queue:false })
    			}
    		
    			if( $obj.getYdir() < 0 ) {
    				$obj.animate({ top: ( pan_y )},{ duration:(1000 * pan_y_time), queue:false })
    			} else {
    				$obj.animate({ top: "0" },{ duration:(1000 * pan_y_time), queue:false })
    			}
		}
	});
//-------------- end cycle plugin with panning effect

//-------------- Begin featured events slider
	var initEvents = true;
	if( $('#featuredEvents').length ){
		$(".featuredEventCtrl").blend();
		$('#featuredEvents').cycle({ 
		    fx:     'scrollHorz', 
		    speed:  400, 
		    timeout: 0, 
		    next:   '.next', 
		    prev:   '.prev',
		    before: function(currSlideElement, nextSlideElement, options, forwardFlag){
				if( initEvents ){ 
					initEvents = !initEvents;
					setTimeout( function(){ $("#featuredEvents > div:eq(0)").fadeIn(400); }, 200);
				} else {
					$(currSlideElement).fadeOut(400);
				}
				$(nextSlideElement).hide();
				//var text =  $('#featuredEvents > div').index(this)+1
				var text = $(this).find('h3').text();

				$('#eventNumber').html( text );
			},
		    after: function(currSlideElement, nextSlideElement, options, forwardFlag){
				$('#featuredEvents').fadeIn(500);
			}
		});

	}
//-------------- end featured events slider

	$('.accordionButton').mouseenter(function(){
		if( $(this).hasClass('on') ){
			$(this).addClass('on_over');
		}
	}).mouseleave( function(){
		$(this).removeClass('on_over');
	});


	$('a#joinstreetteam').click(function() {
		$('#streetbox').toggle(600);
		return false;
	});

	$('a#radiolink').click( function(){
		var url = $(this).attr('href')
		window.open( url ,'mywindow','width=500,height=310');
		return false;
	});


	if( $('#friends_rotator').length ){
		$('#friends').cycle({ 
		    fx:     'fade', 
		    speed:  400, 
		    timeout: 0, 
		    next:   '#friends_rotator .next', 
		    prev:   '#friends_rotator .prev'
		});
	}

	$('#artworkgallery a').each( function(){
		var $container = $(this);
		$container.append('<div class="loading"></div>')
		.find('.loading').height( 50 ).width( 100 );
	});

});


$(window).load( function(){

	//-------------- BIO PAGE 
		$('#bioslides').cycle({
			timeout: 5000,
			speed: 2000
		});
	//-------------- END BIO PAGE 

	//-------------- BEGIN 'MASONRY' PLUGIN

	$('#artworkgallery').masonry();

	var count = 0;

	$('#artworkgallery a .loading').stop().fadeTo(400,0, function(){ 
		var $loading = $(this);
		//setTimeout( function(){ $loading.remove(); }, 400); 
	});

	$('#artworkgallery a').each( function(){
		var $galleryItem = $(this);
		setTimeout( function(){
			$galleryItem.stop().fadeTo( 800, 1 );
			$galleryItem.find('.loading').stop().fadeTo(400,0, function(){ 
				var $loading = $(this);
				setTimeout( function(){ $loading.remove(); }, 400); 
			});

		}, 100 + ( 100 * count ) );
		count = count +1;
	});


//-------------- END 'MASONRY' PLUGIN

});

function clickclear(thisfield, defaulttext) {
		if (thisfield.value == defaulttext) {
			thisfield.value = "";
		}
	}

	function clickrecall(thisfield, defaulttext) {
		if (thisfield.value == "") {
			thisfield.value = defaulttext;
		}
	}
