$(function() {
	//ajax example
	//$.post('?test', {email:'email',user:'user'}, function(response) {
	//	alert(response);
	//});
	
	//ajax example
	//$.get('?get_featured_rant', function(response) {
		//alert(response);
	//});
	
	//each example
	//$("#frm_manage_users input[@type=checkbox]").each(function(){
		//alert($(this).val());
	//});
	
	//menu css style
	$("#menu a").mouseover(MenuOver);
	$("#menu a").mouseout(MenuOut);
	
	//home tabs
	$("#home-tabs a").click(ChangeHomeTabs);
	
	//faq toggle answer
	$(".toggle-faq-answer").click(ToggleFAQAnswer);
	
	//send resource request
	$(".send-request").click(SendRequest);
	
	//recaptcha field customization
	if($("#recaptcha_response_field").length > 0){
		$("#recaptcha_response_field").css({
			'border' : '1px solid #cccccc'								   
		});
		//$("#recaptcha_response_field").attr("onfocus", "imgField(this, 'over')");
		//$("#recaptcha_response_field").attr("onblur", "imgField(this, 'out')");
		
		$("#recaptcha_response_field").focus(function () {
        	$("#recaptcha_response_field").css({
				'border' : '1px solid #1194C0'								   
			});
    	});
		
		$("#recaptcha_response_field").blur(function () {
        	$("#recaptcha_response_field").css({
				'border' : '1px solid #cccccc'								   
			});
    	});

	}
	
	var i = 0;
	
	if($("#slideshow-images").length > 0){
		$('#slideshow-images').cycle({ 
			speed:  2500, 
			timeout: 2500, 
			shuffle:  {left:-300, top:30},
			clip:     'zoom',
			fx:       'fade',
			fit:      '1',
			pager: '#nav',
			before:   SlideshowTransition,
			// callback fn that creates a thumbnail to use as pager anchor 
			pagerAnchorBuilder: function(idx, slide) { 
				i++;
				if(i == 1)
					var class_name = ' class="slideshow-items-over" ';
				else
					var class_name = ' ';
				
				return '<li' + class_name + 'id="slideshow-link' + i + '"><a href="#">' + slide.alt + '</a></li>';
			}  
		});
	}
})

function SendRequest(){
	var resource_id = $(this).attr("id").substr(8);	
	
	$.post(HTTP + 'ajax/?send_request&sid=' + Math.random(), {id:resource_id}, function(response) {
		if(response == 1){
			var parent_p = $("#request-" + resource_id).parent("p");
			$("#request-" + resource_id).remove();
			parent_p.append('<span class="pending">Pending request</span>');
		}
	});
}

function ToggleFAQAnswer(){
	var item_id = $(this).attr("id").substr(9);
	$("#answer-" + item_id).toggle("slow");
}

function ChangeHomeTabs(){
	var link_id = $(this).attr("id").substr(3);
	
	//change css classes to tabs
	$("#home-tabs li").removeClass("current");
	
	//add class to active tab
	$(this).parent("li").addClass("current");
	
	//hide all divs
	$(".tab-content").removeClass("visible");
	
	//display active div
	$("#tab-content" + link_id).addClass("visible");
}

function SlideshowTransition(){
	//disable over class for pagination links
	$("#slideshow-items li").removeClass("slideshow-items-over");
	var item_id = $(this).attr("id").substr(14);
			
	//add over class to active item
	$("#slideshow-link" + item_id).addClass("slideshow-items-over");
	
}

function MenuOver(){
	//the first menu item must have the class with the rounded background; check if this item is the first
	var container = $(this).parent("li");
	var class_name = 'menu-over';
			
	if(container.attr("id") == $("#menu li:first").attr("id"))
		class_name = 'menu-round-over';
		
	$(this).parent("li").attr("class", class_name);
}

function MenuOut(){
	if($(this).parent("li").attr("class") == 'menu-over')
		$(this).parent("li").removeClass('menu-over');
		
	if($(this).parent("li").attr("class") == 'menu-round-over')
		$(this).parent("li").removeClass('menu-round-over');	
}


