jQuery.noConflict();

/*
 * General DOM ready statemenets
 */
jQuery(function($) {
	
	//IE
	if ($.browser.msie){
		//IE6 or lower
		if ($.browser.version <= 6) {
		
			var $shadowLR = $('.l, .r');
			var $shadowTB = $('.t, .b');
		
			$('#nav li').hover(
				function(){ 
					$(this).addClass('hover');
					$shadowLR.navShadowHeight();
					$shadowTB.navShadowWidth();
				},
				function(){
					$(this).removeClass('hover');
					$shadowLR.navShadowHeight();
					$shadowTB.navShadowWidth();
				}
			);
		}
	}
	
	//Opera
	if ($.browser.opera || $.browser.msie){
		//Nav fix
		var $subNav = $('#nav .subnav');
		$subNav.each(function(){
			_width = 0;
			$('> ul > li', this).each(function(){
				_width = (_width > $(this).width())?_width:$(this).width();
			});
			$(this).width(_width);
		});
		ieHeight = document.body.clientHeight;
		$('#sea, #intro-wrap').height(ieHeight )
	}
	
	//Ad fix
	$('.ad:empty').remove();	
	
	//EmptyOnFocus
	$('#meta').emptyOnFocus();
	
	//Cycle Single Images
	$imagesWrapper = $('#images-content, .news-single-img');
	if ($('div', $imagesWrapper).length > 1) $('#images-nav').show();
	
	$('img', $imagesWrapper).each(function(){
		$img = $(this);
		if ($img.height() < 383) {
			$img.css('margin-top', (383-$img.height())/2);
		}
	});
	
	$imagesWrapper.cycle({
		prev:   '#images-nav .prev', 
		next:   '#images-nav .next', 
		timeout: 0 
	});		
	
	//Ads
	$('.ad').cycle({
	    timeout: 10000
	});
	
	//Homepage slideshow
	$('#slideshow .content').cycle({
		timeout: 4000
	});
	
	//Regular Content images
	$content = $('#content.regular');
	if ($content.find('img').length == 0) {
		$content.addClass('short');
	};
	$('.csc-textpic-imagerow').parent().addClass('multiple');
	
	//Navigation / Day
	$('#nav').click(function(event){
		el = event.target;
		switch (el.parentNode.id){
			case 'n-200': 
				document.location.href = el.href+'#'+'d-200';
				return false;
			case 'n-18': 
				document.location.href = el.href+'#'+'d-18';
				return false;
			case 'n-19': 
				document.location.href = el.href+'#'+'d-19';
				return false;
			case 'n-20': 
				document.location.href = el.href+'#'+'d-20';
				return false;
			case 'n-21': 
				document.location.href = el.href+'#'+'d-21';
				return false;
			case 'n-23': 
				document.location.href = el.href+'#'+'d-23';
				return false;
			case 'n-24': 
				document.location.href = el.href+'#'+'d-24';
				return false;
			case 'n-25': 
				document.location.href = el.href+'#'+'d-25';
				return false;			
		}
	});
	
	if (document.getElementById('history')) {
		$('#back-to-artists').click(function(event){
			history.back();
			return false;
		});
	}
	else {
		//Back to Artists
		$('#back-to-artists').click(function(event){
			$('#nav > li').eq(1).addClass('hover');
			event.stopPropagation;
			return false;
		});
	}
	
	//QTip
	$('#news-archive #archive ul li').qtip({
		position: {
                   corner: {
                      target: 'leftMiddle',
                      tooltip: 'rightMiddle'
                   },
                   adjust: { x: -10, y: 0 }
                 },
                 style: { 
                   width: 60,
                   background: '#000',
                   color: 'white',
                   padding: '0',
                   textAlign: 'center',
                   border: {
                     width: 1,
                     radius: 5,
                     color: '#000'
                   },

                 }

                });
});

/*
 * IE6 height problem
 */
(function($){
	$.fn.navShadowHeight = function() {
	    return this.each(function() {
			$(this).css('height',$(this).parent().height()-8);
		});
	};
	$.fn.navShadowWidth = function() {
	    return this.each(function() {
			$(this).css('width',$(this).parent().width()-8);
		});
	};
})(jQuery);

/*
 * Slideshow
 */
(function($){
	$.fn.slideshow = function(options) {
		
		//Setting Defaults
		var defaults = {
			items: $(this).children()
		};
		
		//Merging the options with the defaults
		var options = $.extend(defaults, options);
		
	    return this.each(function() {
			
			var $items = options.items;
			
			//Setting the images widths, heights, and position
			$.each($items, function(){
				_center($(this));
			});
			
		});
		
		//Centering each item
		function _center($item){
			var $img = $('img', $item);
			var $imgWrap = $('.csc-textpic', $item);
			var _width = $img.width();
			var _height = $img.height();
			var $title = $('.csc-header',$item);
		
			//Setting heights
			$item.css({
				'width' 	: _width,
				'height'	: _height+35,
				'margin-top': -_height/2
			});
		
			$title.css('width',_width);
			
			//Vertical Alignment
			if ($imgWrap.is('.csc-textpic-center')) {
				$item.css({
					'left'			: '50%',
					'margin-left'	: -_width/2
				});
			} else if ($imgWrap.is('.csc-textpic-left')) {
				$item.css({
					'left'			: '0'
				});
			}
			
		}
		
	};
})(jQuery);

