/*
* Copyright (C) 2009 Joel Sutherland
* Licenced under the MIT license
* http://www.newmediacampaigns.com/page/
*/
jQuery.fn.nmccorners = function(settings) {
		settings = $.extend({}, settings);
		$(this).each(function(){
			$(this).css('position', 'relative');
			$(this).append('<div class="top-right corner"></div>')
				   .append('<div class="top-left corner"></div>')
				   .append('<div class="bottom-left corner"></div>')
				   .append('<div class="bottom-right corner"></div>');
		});
}

$(document).ready(function(){
	
	$('html:has(.default)').css({
		background: "#5b5b5b url('/~intrahea/css/images/background.jpg') top center",
		backgroundAttachment: "fixed"
	});
	//Twitter
	$.ajax({
		type: 'GET',
		url: 'http://twitter.com/statuses/user_timeline/IntraHealthInt.json?count=1',
		dataType: 'jsonp',
		success: function(json){
			$.each(json, function(i, item){
				$('#tweet').html(item.text);
				$('#tweet').append(item.created_at);
			});
		}
	});

	//IntraHealth Difference Collage
	var listCount = 48 - $('#other-differences li').size();
	for(listCount; listCount>0; listCount--){
		$('#other-differences').append('<li><img class="no-corner" src="../images/face.gif" width="43px" height="43px" alt="" /></li>');
	}
	
	//Resources and Publications Page
	$('#resources-browser').tabs();
	
	$('#open-council ul').makeacolumnlists({cols: 3, colWidth: 0, equalHeight:false, startN: 1});

	
	$('#slides').nmccorners();
	$('#contentcol img:not(".no-corner")').wrap('<div class="nmccorners"></div>');
	$('.nmccorners').each(function() {
		var child = $(this).children().eq(0);
		$(this).css({
			width: child.width(),
			height: child.height(),
			overflow: 'hidden',
			float: child.css('float'),
			marginRight: child.css('margin-right')
		});
		child.css({ }).removeAttr('style');
	});
	$('.nmccorners').nmccorners();	
	
	$('#search .text').focus(function(){
		$(this).css('background', '#dedede').css('color', '#000');
	});
	
	$('#nav li').hover(function(){
		$(this).addClass('hover');
	}, function() {
		$(this).removeClass('hover');
	});
	
	$('#accordion li h4').click(function(){
		if(! $(this).parent().hasClass('open')){
			$(this).parent().siblings().removeClass('open');
			$(this).parent().addClass('open');
		}
	});
	
	$('#artist-names').cycle({});

	$('#slide-holder').cycle({
		fx: 'scrollHorz',
		speed: 300,
		timeout: 10000,
		pager: '#slidecontrol',
		pagerAnchorBuilder: function(idx, slide){
			return '<a href="javascript:void(0);">Slide</a>';
		}
	});
	$('#inset-slides').cycle({
		fx: 'fade',
		timeout: 10000,
		pager: '#inset-frame',
		pagerAnchorBuilder: function(idx, slide){
			return '<a href="javascript:void(0);">Slide</a>';
		}
	});
	
	$('#rotate-experts').cycle({
		fx:'scrollHorz',
		speed: 500,
		timeout:10000
	});	
	
	
	$('#accordion li form input[type=text]').attr('value','E-mail Address...').focus(function(){
		val = $(this).val();
		if( val == 'E-mail Address...'){
			$(this).val('');
			val = '';
		}
	});
	
	$('#accordion li form input[type=submit]').addClass('smallbutton');
	
	$('form#form-2 input[type=text]').css('width', '170px');
	$('form#form-2 input[type=submit]').css('margin','0 0 0 200px');
	
	
	$.ajax({
		type: 'GET',
		url: 'http://twitter.com/statuses/user_timeline/intrahealthopen.json?count=1',
		dataType: 'jsonp',
		success: function(json){
			$.each(json, function(i, item){
				$('#open-tweet').html(item.text);
				$('#open-tweet').append(item.created_at);
			});
		}
	});
	
});