/**
 * Functions for handling the scrolling of the blog teasers in the footer.
 */
var footerBlogsPosition = 0;
function slideFooterBlogs(change) {
	// check new position
	var newval = footerBlogsPosition + change;
	if (newval < 0)
		return; // too low
	if ($('#foot .blogs .blog' + (newval + 2)).size() < 1)
		return; // too high
	// move there
	$("#foot .blogs .contents .fw").animate( {
		left : -(295 * newval)
	}, 500);
	footerBlogsPosition = newval;
}

/**
 * Functions for handling the image grid (onHover) in the footer
 */
function recipegrid_hover(a, name, imgUrl, x, y) {
	// get grid
	var grid = $(a).parents('.recipegrid').get(0);
	var hover = $('.recipegrid-hover', grid);
	// calculate position 
	x -= 25; y -= 30;
	//var x = Math.max(-15, (index % 8) * 120 - 25);
	//var y = (Math.floor(index / 8)) * 90 - 30;
	var linkUrl = $(a).attr('href');
	// move hover div
	$(hover).show().css('left', x + 'px').css('top', y + 'px');
	//$('#foot-recipegrid-hover').show().css('left', x + 'px').css('top',	y + 'px');
	// set new data
	$('h4 a', hover).html(name);
	$('img', hover).attr('src', imgUrl);
	$('a', hover).attr('href', linkUrl);
	return false;
}
function recipegrid_reload(grid, widths, rows, height) {
	// calculate url
	var date = new Date();
	var url = '/ajax/recipegrid/?widths=' + widths + "&rows=" + rows + "&height=" + height + "&" + date.getTime();
	$('.contents', grid).load(url);
}

/**
* Properties for predefined popup windows
*/
var popupClasses = {
	poll : "height=580,width=580,scrollbars=1,resizable=1",
	multipoll : "height=580,width=580,scrollbars=1,resizable=1",
	sendto : "height=700,width=580,scrollbars=1,resizable=1",
	popupPrint : "height=700,width=580,scrollbars=1,resizable=1",
	standard : "height=700,width=580,scrollbars=1,resizable=1",
	oldsite : "height=700,width=740,scrollbars=1,resizable=1"
};


/**
* Method used to submit form data to new windows.
*/
function submitToNewWindow(form, winName, noSubmit) {
	if (!winName)
		winName = "standard";
	if (form) {
		// get windows params
		var winParams = popupClasses[winName];
		if (winParams == null)
			winParams = popupClasses["standard"];
		// open new window
		newWindow = window.open("", winName, winParams);
		// submit to this window
		form.target = winName;
		if (noSubmit == true)
			return;
		form.submit();
	}
}

function CM8ShowAd() { } 

$(function() {
	var formid = '#sendtoform';
	$(formid).submit(function() {
	    var to_email = $(formid+' .to_email').val();
	    var message = $(formid+' .message').val();
	    var from_email = $(formid+' .from_email').val();
	    var from_name = $(formid+' .from_name').val();
	    var url = $(formid+' .url').val();
	    var title = $(formid+' .title').val();
	    
	    $.ajaxSetup({ scriptCharset: "utf-8" , contentType: "application/json; charset=utf-8" });
	    $.getJSON(
	    		$(formid).attr('action'), 
	    		{ to_email: to_email, message: message, from_name: from_name, from_email: from_email, url: url, title: title},
	    		function(data, status){ 
	    			alert(data.msg);
	    			if(data.success) $(formid).hide();
	    		}
	    );
	    return false;
	});
});
$(function() {
	var formid = '#sendsmsform';
	$(formid).submit(function() {
	    var to = $(formid+' .to').val();
	    var recipe = $(formid+' .recipe').val();
	    $.getJSON(
	    		$(formid).attr('action'), 
	    		{ to: to, recipe: recipe},
	    		function(data, status){ 
	    			alert(data.msg);
	    			if(data.success) $(formid).hide();
	    		}
	    );
	    return false;
	});
});