// JavaScript Document
jQuery.fn.studentprofile = function() {
 	this.each(function(){
		if (document.location.href.indexOf('/meet-a-major') < 0 && document.location.href.indexOf('/study-abroad/student') < 0 && document.location.href.indexOf('/academic-support/meet-a-tutor') < 0){
		var colors = ['#00b2ed','#004e73','#440088','#cdb700'];
		var dataUrl = 'http://assets.nwciowa.edu/nwciowa/xml/student-profiles.aspx';
		var $self = $(this);
		var dept = $(this).attr('id').replace('studentprofile-', '');
		$self.bind('render', function(event,data){
			var url  = dataUrl + '?dept=' + dept + '&r=' + Number(new Date()) + '&callback=?';
			$.getJSON(url,function(json){ 
				if (json.id){
					$self.append('<a href="' + json.url + '"><img border="0" alt="" src="' + json.photo + '"/></a>');
					$self.append('<strong>' + json.name + '</strong><p>' + json.abstr + ' <a href="' + json.url + '">More &hellip;</a></p>');
					
				}
				
			});
		});
		$(this).trigger('render', {});
		}
  	});
};


jQuery.fn.campustour = function() {
 	this.each(function(){
		var $self = $(this);
		var dept = $(this).attr('id').replace('studentprofile-', '');
		$self.html('<object width="200" height="200"><param name="movie" value="http://assets.nwciowa.edu/nwciowa/swf/campustour.swf?v=1"><embed src="http://assets.nwciowa.edu/nwciowa/swf/campustour.swf?v=2" width="200" height="200"></embed></object>');
  	});
};

$(function(){
	$('.raiderblogs-ticker').each(function(){
		var $self = $(this);
		$self.find('ul').wrap('<div class=\"blog-container\"></div>');
		var numChildren = $self.find('li').length;
		var currentChildIndex = 0;
		$self.find('li').each(function(){
			var $child = $(this);
			var $link = $child.find('a').hide();
			$child.prepend('<strong>' + $link.text() + '</strong>');
			$child.append('<a rel="external" href="' + $link.attr('href') + '">Visit blog</a>');
		});
		$self.append('<div class="more-blogs"><a href="/blogs">More blogs</a>');
		

		$buttons = $('<div class="toggle-buttons"></div>').appendTo($self);
		
		$prev = $('<a class="prev"></a>').appendTo($buttons).click(function(){
			$self.find('.next').removeAttr('disabled');
			var prev = (currentChildIndex == 0) ? numChildren-1 : currentChildIndex-1;
				$self.find('li').eq(currentChildIndex).fadeOut();
				$self.find('li').eq(prev).fadeIn();
				currentChildIndex = prev;
		});
		$next = $('<a class="next"></a>').appendTo($buttons).click(function(){
			$self.find('.prev').removeAttr('disabled');
			var next = (currentChildIndex == numChildren-1) ? 0 : currentChildIndex+1;
				$self.find('li').eq(currentChildIndex).fadeOut();
				$self.find('li').eq(next).fadeIn();
				currentChildIndex = next;
				
		});
		$self.find('li').eq(currentChildIndex).fadeIn();
		
	});
	
	$('.studentprofile').studentprofile();
	//$('.campustour').campustour();
	/**
	$('.student-profile-photo').click(function(){
		if ($(this).css('float') == 'right'){
			$(this).css({'display':'block','float':'none','border':'1px solid #eee','background':'#f2f2f2','margin':'0px','height':'265px'}).animate({'width':470}).find('img').hide();
			$('.content-photo').slideUp();
		}else{
			$(this).css({'display':'block','float':'right','border':'0px','background':'none','margin':'0px 0px 12px 12px','height':'265px'}).animate({'width':265}).find('img').fadeIn();
			$('.content-photo').slideDown();
		}
	});
	**/
});