/*
 *	StudentCity 2010
 *	Common JS functions
 *  Author: Ryan Zec
 *	Author: TJ Kelly - www.tjkelly.com
 */

$(document).ready(function(){

	// Include Enriched CSS
	//$('<link rel="stylesheet" type="text/css" href="/api/css/enriched.css" /><link rel="stylesheet" type="text/css" href="http://dev.studentcity.com/lib/css/2010-enriched.css" />').appendTo('head');

/*
	if($('#your_experience_includes_more a').length > 0){
		$('#your_experience_includes_more a').click(function(){
			$(this).parent().siblings('.expandable_list').removeClass('hide');
			$(this).parent().remove();
			return false;
		});
	}

	// Rel External for new window
	var $a=$('a[rel*="external"]');
	$a.attr('target','_blank');
*/

	// Booking incentives fancyboxes
	if($('div.booking_incentives').length > 0){
		$('div.booking_incentives a.fancybox').fancybox({
			'hideOnContentClick' : false,
			'zoomOpacity' : true,
			'zoomSpeedIn' : 300,
			'zoomSpeedOut' : 300,
			'padding' : 0,
			frameWidth :	600,
			frameHeight :	484 // must be 20px smaller than desired height. 324 will create a box of 344, etc
		});
	}
	
});

function in_array(find, search)
{
	if(search && search.length > 0)
	{
		for(var x = 0; x < search.length; x++)
		{
			if(find == search[x])
			{
				return true;
			}
		}
	}

	return false;
}

function add_commas(number)
{
	number += '';
	x = number.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

function remove_commas(number)
{
	number += '';
	return number.replace(',', '');
}

function form_to_json(form_id)
{
	var o = {};
	var a = $('#' + form_id).serializeArray();
	$.each(a, function() {
		if (o[this.name]) {
			if (!o[this.name].push) {
			    o[this.name] = [o[this.name]];
			}
			o[this.name].push(this.value || '');
		} else {
			o[this.name] = this.value || '';
		}
	});
	return o;
};
