// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
var gluten_bar_current_index = 3;
var img_srcs = new Array();
var img_types = new Array();
var hrefs = new Array();

$j= jQuery.noConflict();
$j.ajaxSetup({ 
  'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")}
});

//Converts common pagination into ajax pagination
function formatLinkForPaginationURL() {
	$("div.pagination a.next_page").click(function() {
	    var linkElement = $( this );
	    var paginationURL = linkElement.attr("href");
	    linkElement.attr({"url": paginationURL,"href": "#"});
	    
	    $.post('/events/posts/' + name + '?page=' + linkElement.attr("page"),null, function(data){
			$("#posts").html(data);
		});
		return false;		
	});
		
	$("div.pagination a.previous_page").click(function() {
	    var linkElement = $( this );
	    var paginationURL = linkElement.attr("href");
	    linkElement.attr({"url": paginationURL,"href": "#"});
	    
	    $.post('/events/posts/' + name + '?page=' + linkElement.attr("page"),null, function(data){
			$("#posts").html(data);
		});
		return false;		
	});
}

function hideCanadianProvince(recordId, canadaCountryConstant){
	if(document.getElementById('record_country_' + recordId).value == canadaCountryConstant){
		document.getElementById('canadianProvinceDiv_' + recordId).style.visibility = "visible";
	}else{
		document.getElementById('canadianProvinceDiv_' + recordId).style.visibility = "hidden";
	}
}

/*Blog rating mouse over*/	
function mouse_over_star(rating, blogPost){
	var i = 1;
	for (i ; i <= rating; i++) {
		if (document.getElementById('a_' + i + '_star_off_' + blogPost) != null) {
			document.getElementById('a_' + i + '_star_off_' + blogPost).className = 'star_on';

		}
	}
}
	/*Blog rating mouse out*/		
function mouse_out_star(rating, blogPost){
	for (var i = 1; i <= rating; i++) {
		if (document.getElementById('a_' + i + '_star_off_' + blogPost) != null) {
			document.getElementById('a_' + i + '_star_off_' + blogPost).className = 'star_off';
		}else{
			document.getElementById('a_' + i + '_star_on_' + blogPost).className = 'star_on';
		}
	}
}


function swap_classes(div_id1, class1, div_id2, class2) {
	document.getElementById(div_id1).className = class1;
	document.getElementById(div_id2).className = class2;
}

function gluten_bars_up(){
	if (gluten_bar_current_index > 0)
	{
	    jQuery("#bar" + gluten_bar_current_index).animate({ 
    	    width: "100px",
    	    height: "41px",
			opacity: 0.5
	    }, 500 );

		gluten_bar_current_index -= 1;
	    jQuery("#bar" + gluten_bar_current_index).animate({ 
    	    width: "170px",
    	    height: "70px",
			opacity: 1
	    }, 500 );

	    jQuery("#gluten_bars_papyrus").animate({ 
    	    top: "+=42px"
	    }, 500 );

	    /*jQuery("#gluten_bar_info").animate({ 
			opacity: 0.5
	    }, 200, function() {*/
			var img_bar_type = document.getElementById('img_bar_type');
			img_bar_type.src = "/images/gluten_free/" + img_types[gluten_bar_current_index] + "_label.png";
			var img_bar_title = document.getElementById('img_bar_title');
			img_bar_title.src = img_srcs[gluten_bar_current_index];
			var gluten_go_btn = document.getElementById('gluten_go_btn');
			gluten_go_btn.href = hrefs[gluten_bar_current_index];
			
		    /*jQuery("#gluten_bar_info").animate({ 
				opacity: 1
		    }, 200 );
		} );*/
	}
}

function gluten_bars_down(){
	var puede_bajar = document.getElementById('bar' + (gluten_bar_current_index + 1));
	if (puede_bajar != null) {

	    jQuery("#bar" + gluten_bar_current_index).animate({ 
    	    width: "100px",
    	    height: "41px",
			opacity: 0.5
	    }, 500 );
	
		gluten_bar_current_index += 1;
	    jQuery("#bar" + gluten_bar_current_index).animate({ 
    	    width: "170px",
    	    height: "70px",
			opacity: 1
	    }, 500 );
	
	    jQuery("#gluten_bars_papyrus").animate({ 
    	    top: "-=42px"
	    }, 500 );
		
	    /*jQuery("#gluten_bar_info").animate({ 
			opacity: 0.5
	    }, 200, function() {*/
			var img_bar_type = document.getElementById('img_bar_type');
			img_bar_type.src = "/images/gluten_free/" + img_types[gluten_bar_current_index] + "_label.png";
			var img_bar_title = document.getElementById('img_bar_title');
			img_bar_title.src = img_srcs[gluten_bar_current_index];
			var gluten_go_btn = document.getElementById('gluten_go_btn');
			gluten_go_btn.href = hrefs[gluten_bar_current_index];
			
		    /*jQuery("#gluten_bar_info").animate({ 
				opacity: 1
		    }, 200 );
		} );*/

	}
}

function add_img_href(src, href, type) {
	img_srcs.push(src);
	img_types.push(type);
	hrefs.push(href);
}

