/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   jQuery Functions for TCI TeacherGenius
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
//var $ = jQuery;
$(document).ready(function (){
							
// Home page - Wrap each set of 4 .bundle DIVs in a DIV called 'row'
	var results =[];
	var elements = $("body.archive .bundle").children("div");
	$.map(elements, function(i, n){
		if( n%4 === 0 ){
			results.push(n);
		}
	});
	$.each(results, function(i,v){
		elements.slice(v, v+4).wrapAll("<div class=\"row\"></div>");
	});

// Remove subnav divider line from last menu item		
	$("#snav ul").each(function(){
		$(this).find("li a").filter(":last").css({
			"border-right":"none",
			"margin-right":"0",
			"padding-right":"0"
		});
	});
	
// Top/Related Submissions Sidebar row coloring - using "odd" to select "even" cells because numbering starts at zero.
	$("#sidebar ol li:odd").addClass("even");
	
// Designate "first" comment in list; also even/odd for striping
	$(".comments li:first").addClass("first");
	$(".comments li:last").addClass("last");
	$(".comments li:odd(:not(:first))").addClass("stripe");
	
	$("#sidebar .genius-info .second li:last, #submission .second li:last").css({
		"border-bottom":"none",
		"margin-bottom":"0",
		"padding-bottom":"0"
	});
	
// Wrap text of subnav items in a SPAN so that the bottom border applied on hover and active are confined to just the text, not the entire LI.
	$("#snav li a").wrapInner("<span></span>");
	
// Category page: Add margins between .unit boxes, except for the last one, for each .row.
	$("body.archive .row").each(function(){
		$(this).find(".unit").filter(":last").css("margin-right","0");
	});	
	
// Remove border from radio buttons/checkboxes in IE
	$("#gform_fields_1 input[type=checkbox]").css("border","none");
	
	
// QTIP - Tooltips	
	$.fn.qtip.styles.tipStyle = { // Last part is the name of the style
		padding: "5px 10px",
		"font-size":"14px",
		background: '#ddd',
		color: 'black',
		textAlign: 'center',
		border: {
			width: 7,
			radius: 5,
			color: '#ddd'
		},
		tip: 'bottomMiddle',
		name: 'dark' // Inherit the rest of the attributes from the preset dark style
	}
		
	assignQTip(".row .unit .enrichment-resources", "Enrichment Resource");
	assignQTip(".row .unit .lesson-adaptations", "Lesson Adaptations");
	assignQTip(".row .unit .teaching-tips", "Teaching Tip");
	assignQTip(".row .unit .videos", "Video");
	assignQTip(".row .unit .websites", "Website");
	assignQTip(".row .unit .biography-bank", "Biography Bank");
	assignQTip(".row .unit .professional-development", "Professional Development");

}); // END OF Document. Functions go after this line.

function assignQTip(selector, message) {
	var position = {
			corner: {
				target: "topMiddle",
				tooltip: "bottomMiddle"
			} 
		};
	$(selector).qtip({
		content: message,
		position: position,
		style: "tipStyle"
	});
}


