var $j = jQuery.noConflict();
$j(document).ready(function(){
	// search field events
	var sf = $j('#s'), sfd = $j('#search-field');
	sf.focus(function(){
		sf.addClass('search-focus');
		sfd.addClass('search-focus');
		if(sf.val() == 'Search...'){
			sf.val('');
		}
		sf.select();
	});
	sf.blur(function(){
		sf.removeClass('search-focus');
		sfd.removeClass('search-focus');
		if(sf.val() == ''){
			sf.val('Search...');
		}
	});
	
	// rotator init
	initRotator();
	
	// wire up lightbox
	var lb = $j('a.lightbox');
	if(lb.length){
		lb.lightBox();
	}
	
	// wire up plain colorbox
	$j('a.cb').colorbox();
	
	// wire up video iframe colorbox
	var cbi = $j('a.cb-vid');
	if(cbi.length){
		$j.each(cbi, function(i, n){
			var $n = $j(n),
				iw = $n.data('vw'),
				ih = $n.data('vh')
				;
			$n.colorbox({
				iframe: true,
				innerWidth: iw,
				innerHeight: ih+25,
				onComplete: function(){
					var th = $j('#cboxTitle').height(),
						delH = th > 16 ? th - 16 : 0,
						cb = $j('#colorbox'),
						cbW = $j('#cboxWrapper'),
						cbC = $j('#cboxContent'),
						cbML = $j('#cboxMiddleLeft'),
						cbMR = $j('#cboxMiddleRight'),
						cbLC = $j('#cboxLoadedContent');
					cbLC.css('margin-bottom', th + 4);
					cb.height(cbW.height() + delH);
					cbW.height(cbW.height() + delH);
					cbC.height(cbC.height() + delH);
					cbML.height(cbML.height() + delH);
					cbMR.height(cbMR.height() + delH);
					
				}
			});
		});
	}
	
	// wire up qt 360 colorbox
	var cbq = $j('a.cb-qt');
	if(cbq.length){
		$j.each(cbq, function(i, n){
			var $n = $j(n);
			$n.colorbox({
				html: '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"'
        				+ ' codebase="http://www.apple.com/qtactivex/qtplugin.cab"'
        				+ ' width="920"'
        				+ ' height="540">'
					+ '<param name="src" value="' + this.href + '">'
					+ '<param name="autoplay" value="true">'
					+ '<param name="controller" value="false">'
					+ '<param name="type" value="video/quicktime">'
					+ '<param name="scale" value="0.8">'
					+ '<embed src="' + this.href + '" controller="false"'
					+ ' autoplay="true" type="video/quicktime" scale="0.8"'
					+ ' pluginspage="http://www.apple.com/quicktime/download/" width="920" height="540">'
					+ '</object>'
			});
		});
	}

	// contact form events
	
	
});

// rotator
var rd, rdFirst, rInt, rTran;
function initRotator(rd){
	rd = $j('#rotator div');
	rdFirst = rd.first();
	rInt = 7000;
	rTran = 1000;
	if(rd.length){
		rd.css({opacity: 0.0});
		rdFirst.css({opacity: 1.0}).addClass('show');
		if(rd.length > 1){
			setInterval('rotate()', rInt);
		}
	}
}
function rotate() {
	var shown = $j('#rotator div.show');
	var curr = (shown ?  shown : rdFirst);
	var next = (curr.next().length ? (curr.next().hasClass('show') ? rdFirst : curr.next()) : rdFirst);	
	next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, rTran);
	curr.animate({opacity: 0.0}, rTran).removeClass('show');
};
	
	
