$j = jQuery.noConflict();
$j(document).ready(function() {
	
	/* WORDPRESS JAVASCRIPT */
	/* Landing Page */
	$j('#exp-home li').click(function(){
		location.href = $j(this).find('a').attr('href');
	});
	
	/* In the press */
	$j('#itp li a').lightBox({
		imageLoading: '/the-experience/wp-content/themes/dc/images/lightbox-ico-loading.gif', 
		imageBtnPrev: '/the-experience/wp-content/themes/dc/images/lightbox-btn-prev.png', 
		imageBtnNext: '/the-experience/wp-content/themes/dc/images/lightbox-btn-next.png' 
	});
	
	$j('#itp li').hover(function() {
		$j(this).find('.hover').fadeIn();
	},
	function() {
		$j(this).find('.hover').fadeOut();
	});
	
	/* Our Story & Events */
	function centerBigImage() {
		var width = $j('#big-image').width();
		var height = $j('#big-image').height();
		var newHeight = (height / 2) * -1 + 7;
		var newWidth = (width / 2) * -1;
		$j('#big-image').css('marginTop',newHeight);
		$j('#big-image').css('marginRight',newWidth);
		if( !$j('#big-image').is(':visible') ) {
			$j('#big-image').show();
		}
	}
	
	//setTimeout(centerBigImage,1000);
	
	function loadBigImage(src,counter) {
		$j('#big-image').hide();
		$j('#loader').show();
		$j('#big-image').attr('alt', counter);
		var ImageUrl = src;
		var NewImage = new Image();
    	NewImage.onload = function() {
	   		$j('#big-image').attr('src', ImageUrl);
	   		//centerBigImage();
	   		$j('#big-image').show();
	   		$j('#loader').hide();
	   	}
    	NewImage.src = ImageUrl;
	}
	
	$j('ul#current-thumbs li a.thumb-pic').livequery('click', function() {
		var counter = $j(this).attr('rel');
		var ImageUrl = $j(this).attr('href');
		loadBigImage(ImageUrl,counter);
		return false;
	});
	
	$j('#right #next-btn').livequery('click', function() {
		var firstImage = '';
		var imageSet = false;
		var current = $j('#big-image').attr('alt');
		next = parseInt(current) + 1;
		firstImage = $j('ul#current-thumbs li a.thumb-pic:nth-child(1)').attr('href');
		if( next.toString() > $j('ul#current-thumbs li a.thumb-pic:last').attr('rel') ) {
			loadBigImage(firstImage,'1');
			return false;
		} else {
			var image = $j('ul#current-thumbs li:nth-child('+next+') a').attr('href');
			loadBigImage(image,next.toString());
		}
		return false;
	});
	
	$j('#right #prev-btn').livequery('click', function() {
		var lastImage = '';
		var imageSet = false;
		var current = $j('#big-image').attr('alt');
		next = parseInt(current) - 1;
		if( next == 0 ) {
			lastImage = $j('ul#current-thumbs li a.thumb-pic:last').attr('href');
			current = $j('ul#current-thumbs li a.thumb-pic:last').attr('rel');
			loadBigImage(lastImage,current);
			return false;
		} else {
			$j('ul#current-thumbs li a.thumb-pic').each(function() {
				if( this.rel == next.toString() ) {
					var image = this.href;
					loadBigImage(image,next);
				}
			});		
		}
		return false;
	});
	
	$j('.events .sociable').remove();
	
	$j('.event span.move, .event h3').livequery('click', function() {
		$j('.event').removeClass('event-open');
		$j('.event .content').slideUp();
		$j(this).parent().find('.content').slideDown();
		$j('.event').find('ul').attr('id','');
		$j(this).parent().addClass('event-open');
		$j(this).parent().find('ul').attr('id','current-thumbs');
		var image = $j(this).parent().find('ul#current-thumbs li a:first').attr('href');
		loadBigImage(image,'1');
		return false;
	});
	
	$j('#events-nav .next-btn').livequery('click', function() {
		var next = parseInt($j('.event-open').attr('id').replace('event_',''));
		next++;
		var size = $j('.event .content').size();
		$j('.event').find('ul').attr('id','');
		$j('.event').removeClass('event-open');
		$j('.event .content').hide();
		if( next > size ) {
			var event = "#event_1";
		} else {
			var event = "#event_" + next;
		}
		$j(event).addClass('event-open');
		$j(event + ' .content').slideDown();
		$j(event).find('ul').attr('id','current-thumbs');
		var image = $j(event).find('ul#current-thumbs li a:first').attr('href');
		loadBigImage(image,'1');
		return false;
	});
	
	$j('#events-nav .prev-btn').livequery('click', function() {
		var next = parseInt($j('.event-open').attr('id').replace('event_',''));
		next--;
		var size = $j('.event .content').size();
		$j('.event').find('ul').attr('id','');
		$j('.event').removeClass('event-open');
		$j('.event .content').hide();
		if( next == 0 ) {
			var event = "#event_" + size;
		} else {
			var event = "#event_" + next;
		}
		$j(event).addClass('event-open');
		$j(event + ' .content').slideDown();
		$j(event).find('ul').attr('id','current-thumbs');
		var image = $j(event).find('ul#current-thumbs li a:first').attr('href');
		loadBigImage(image,'1');
		return false;
	});
	
	/* Collections */
//	var marTop = $j('ul#collections li img').css('marginTop').replace("px", "");
	var marTop = 107;
//	var liWidth = $j('ul#collections li').css('width').replace("px", "");
	var liWidth = 300;
	var navWidth = liWidth;
	var ulWidth = ($j('ul#collections li').size() * liWidth * -1) + navWidth;
	var center = 2; //starts out with the first element
		
	$j('.previous').click(function() {
	    var currentPos = $j('ul#collections').css("left").replace("px", "");
	    if( !$j('ul#collections li:eq('+1+')').hasClass('center') ) {
	    	$j('ul#collections').animate({"left": "+="+navWidth+"px"}, {queue: 'false', duration: 800});	
	    	$j('ul#collections li:eq('+(center)+') img').animate({height: '50%', width: '50%', marginTop: marTop}, {queue: 'false'});
	    	$j('ul#collections li:eq('+(center)+')').removeClass('center');
	    	center--;
	    	$j('ul#collections li:eq('+(center)+') img').animate({height: '99%', width: '100%', marginTop: '0'}, {queue: 'false'});
	    	$j('ul#collections li:eq('+(center)+')').addClass('center');
			$j('#pop-up').remove();
	    } else if(currentPos == 0) {
	    	//$j(this).css({'color' : '#333'});
	    }
	    return false;
	});
	
	$j('.next').click(function() {
	    var currentPos = $j('ul#collections').css("left").replace("px", "");
	    //if(((currentPos/navWidth)+265) > (ulWidth/(navWidth)) ) {
	    if( !$j('ul#collections li:last-child').hasClass('center') ) {
	    	$j('ul#collections').animate({"left": "-="+navWidth+"px"}, {queue: 'false', duration: 800});
	    	$j('ul#collections li:eq('+(center)+') img').animate({height: '50%', width: '50%', marginTop: marTop}, {queue: 'false'});
	    	$j('ul#collections li:eq('+(center)+')').removeClass('center');
	    	center++;
	    	$j('ul#collections li:eq('+(center)+') img').animate({height: '99%', width: '100%', marginTop: '0'}, {queue: 'false'});
	    	$j('ul#collections li:eq('+(center)+')').addClass('center');
			$j('#pop-up').remove();
	    } else {
	    	//$j(this).css({'color' : '#333'});
	    }
	    return false;
	});

	$j('.pop-up').hover(function() {
		var mapName = $j(this).parent().attr('name');
		var centerMap = $j('ul#collections li.center img').attr('usemap').replace("#","");
		if( mapName != centerMap ) return; 
		$j('#pop-up').remove();
		var coords = $j(this).attr('coords');
		coords = coords.split(',');
		var y = coords[1];
		var x = coords[2];
		if( x > '150' ) {
			x = '80';
		} else {
			x = '0';
		}
		$j('ul#collections li.center').append('<div style="position: absolute; top: '+y+'px; right: -'+x+'px;" id="pop-up"><p class="top" /><div class="inner"><p class="arrow" /><div class="product">'+$j(this).attr('alt')+'</div><button class="button" onclick="window.location.href=\''+$j(this).attr('href')+'\'"><span>Read More</span></button><p class="bottom" /></div></div>');
	});

});
