/////////
//	Girl Page Gallery
///////////////////////////
function hottest_girl_vote(form_id)
{
	document.getElementById(form_id).submit();
}

function showPicture(index)
{
	pics_wrap.select('img:not([class=hide])').invoke('addClassName', 'hide');
	thumb_wrap.select('.selected').invoke('removeClassName', 'selected');

	Element.removeClassName(pics[index], 'hide');
	Element.addClassName(thumbs[index], 'selected');
}

var gal, slide, scroll;

function init_gallery()
{
	gal = new ImageGallery({
			thumbPrefix: 'sml_',
			imagePrefix: 'img_',
			selectedClass: 'selected',
			thumbClass: 'thumb'
	});
	
	slide = new Slidezilla('pic_more', {
			num_visible: 7,
			increment: 1,
			content_class: 'pics_wrap',
			up_class: 'arrow_top',
			down_class: 'arrow_down'
	});

//	scroll = new scrollwheel( { container_id: 'pics_wrap', callback: scroll_callback } );
}

function scroll_callback(e, d)
{
	if(d > 0)
		imgPrevious();
	else if(d < 0)
		imgNext();
}

function imgPrevious()
{
	reloadAd('billboardAd', 300, 250);
	reloadAd('banner', 728, 90);
	gal.showPrevious();
	slide.up();
}

function imgNext()
{
	reloadAd('billboardAd', 300, 250);
	reloadAd('banner', 728, 90);
	gal.showNext();
	slide.down();
}


//////
//	Application
////////////////////
function step_one()
{
	var form = $('step_one');

	form.submit();

//	var form_values = form.serialize();

//	new Req.ajax({ div: 'steps', url: '/ajax/cute_college_girl/apply_info', options: { parameters: form_values } });
}

function showMessage(pic_type)
{
	$(pic_type + '_upload_message').update('Hang on, this might take a minute....');
}

function delete_hottest_girl_media_file(girl_id, girl_hash, hottest_girl_media_file_id, calling_source) {
    var calling_source = (calling_source === undefined) ? "apply_form" : calling_source;

	new Req.ajax(
        {
            url: '/ajax/hottest_girl/delete_hottest_girl_media_file', 
            options: { parameters: 'girl_id=' + girl_id + '&hash=' + girl_hash + '&hottest_girl_media_file_id='+hottest_girl_media_file_id+'&calling_source='+calling_source} 
        }
    );
}

function update_status(girl_id, from_bucket){

    var form_id = 'update_status_' + girl_id;

    params = 'girl_count='+girl_count+'&'+Form.serialize(form_id);
    girl_count = girl_count - 1;

    new Req.ajax({
                url: '/ajax/hottest_girl.admin/update_status/',
                options: {parameters:params}
    });


}

function update_girl_info() {
    
    new Req.ajax({
        url: '/ajax/hottest_girl/update_girl_info', 
        options: { parameters: Form.serialize('girl_info')} 
    });

}

function update_girl_interview() {
    
    $('submit_interview').disabled = true;
    $('girl_interview_status').innerHTML = "<span style='font-size:italic'>Saving Interview...</span>";
    new Req.ajax({
        url: '/ajax/hottest_girl/update_girl_interview', 
        options: { parameters: Form.serialize('girl_interview'),
                   onComplete: function() {
                       $('submit_interview').disabled = false;
                   }
                       
                 } 
    });

}

/* FANTASY BRACKET */

function make_pick(matchup_id, girl_id, contest_year, child_matchup_id) {
	var tmp_image = '<img src="/clients/hottestgirl2k7/artwork/hg_ftsy_loading_pic.gif"/>';
    if(child_matchup_id)
        $('matchup' + child_matchup_id).innerHTML ='<div class="top">' + tmp_image + '</div>' + '<div class="bottom">' + tmp_image + '</div>';
    else
        $('matchup_final_winner').innerHTML ='<div class="top">' + tmp_image + '</div>' + '<div class="bottom">' + tmp_image + '</div>';

    new Req.ajax({
                url: '/ajax/hottest_girl/fantasy_bracket_make_pick/',
                //debug: true,
                options: {
                    parameters: 'matchup_id=' + matchup_id + '&girl_id=' + girl_id + '&contest_year=' + contest_year
                }
    });
}

function load_picks(data)
{
	if (data.keys)
	{
		while (data.keys.length)
		{
			var id = data.keys.pop();
			$('matchup' + id).innerHTML = data['data'][id];
			
			if (id == '121')
				$('north_winner').innerHTML = data['data'][id];
			if (id == '122')
				$('south_winner').innerHTML = data['data'][id];
			if (id == '123')
				$('east_winner').innerHTML = data['data'][id];
			if (id == '124')
				$('west_winner').innerHTML = data['data'][id];
		}
	}
	
	if (data.total_picks && data.can_edit)
		update_pick_count(data.total_picks, true);
}

function load_picks_old(data)
{
	if (data.keys)
	{
		while (data.keys.length)
		{
			var id = data.keys.pop();
			if(id < 121){
				$('matchup' + id).innerHTML = data['data'][id];
			}else{
				if (id == '121')
					$('north_winner').innerHTML = data['data'][id];
				if (id == '122')
					$('south_winner').innerHTML = data['data'][id];
				if (id == '123')
					$('east_winner').innerHTML = data['data'][id];
				if (id == '124')
					$('west_winner').innerHTML = data['data'][id];
			}
		}		
	}
	
	if (data.total_picks && data.can_edit)
		update_pick_count(data.total_picks, true);
}

function update_pick_count(count, show_submit)
{
	//$('pickscounter').innerHTML = count;
	
	count = parseInt(count);

	//show our submit link?	
	if (count == 63){
		if (show_submit)
			$('fantasy_message').innerHTML = '<a href="#" id="submit_picks" onclick="return submit_picks()" class="submit_inactive">Submit Picks</a>';
		$('remaining').innerHTML = 'all done';
	}else if (count == 62){
		$('remaining').innerHTML = '1 remaining';
		$('fantasy_message').innerHTML = '';
	}else{
		$('remaining').innerHTML = (63 - count) + ' remaining';
		$('fantasy_message').innerHTML = '';
	}
	var percent = Math.round(100 * count / 63);
	
	$('fantasy_bar').style.width = (percent-1) + '%';
}

function submit_picks()
{
	$('fantasy_message').innerHTML = "Your bracket has been saved!";
	// new Ajax.Updater('fantasy_message', '/hottestgirl/savepicks', { method: 'GET' });
	//new Ajax.Updater('fantasy_message', '/hottestgirl2007/savepicks', { method: 'GET' });	
	return false;
}

function show_error(error)
{
	$('errors').innerHTML = error;
	$('errors').show();

	setTimeout(hide_error, 3000);
}

function hide_error()
{
	$('errors').hide();	
}

function showBracket(area)
{
	$('north').hide();
	$('south').hide();
	$('east').hide();
	$('west').hide();
    $('final4').hide();

	$(area).show();
}

var hg_form_submitted = false;
function handle_hg_form()
{
	if (hg_form_submitted)
		return false;
	else
	{
		$('submit').disabled = true;
		$('submit').value = 'Please wait...';
		hg_form_submitted = true;
	
		return true;
	}
}

function create_heatmap(girl_id, match_id)
{
	if (GBrowserIsCompatible())
	{
		
		
		var map = new GMap2($('heatmap' + girl_id));
		map.setCenter(new GLatLng(37.7186, -95.9765), 3);

		map.disableDragging();
		map.setMapType(G_NORMAL_MAP);
		
		var heatmap = new Heatmap(girl_id, match_id);
		map.addOverlay(heatmap);
		
		/*
		GEvent.addListener(map, 'click', function (marker, point) {
			console.log(point.lat() + ' ' + point.lng());			
		});
		*/

		/*
		var bounds = map.getBounds();
		var sw = bounds.getSouthWest();
		var ne = bounds.getNorthEast();	
		$('message').innerHTML = sw.lat() + ' ' + sw.lng() + ' ' + ne.lat() + ' ' + ne.lng();
		*/
	}
}

function hideimage(id)
{
//	new Ajax.Request('/hottestgirl/hideimage:' + id, {'method': 'GET'});
	new Ajax.Request('/hottestgirl2007/hideimage:' + id, {'method': 'GET'});
	
	$('unlive_' + id).innerHTML = 'its unlive';
	$('unlive_' + id).style.color = 'red';
	Element.hide('setprofile_' + id);
}

function showimage(id)
{
//	new Ajax.Request('/hottestgirl/showimage:' + id, {'method': 'GET'});
	new Ajax.Request('/hottestgirl2007/showimage:' + id, {'method': 'GET'});
	
	$('makelive_' + id).innerHTML = 'its alive!';
	$('makelive_' + id).style.color = 'red';
}

function setprofile(id)
{
//	new Ajax.Request('/hottestgirl/setprofile:' + id, {'method': 'GET'});
	new Ajax.Request('/hottestgirl2007/setprofile:' + id, {'method': 'GET'});	
	$('setprofile_' + id).innerHTML = 'done';
}

function save_quote(id)
{
//	new Ajax.Request("/hottestgirl/setquote:" + id + '/' + Form.Element.getValue('vote_quote'), {
	new Ajax.Request("/hottestgirl2007/setquote:" + id + '/' + Form.Element.getValue('vote_quote'), {		
		onComplete: save_quote_callback,
		method: 'GET'
	});
}

function save_quote_callback()
{
	$('vote_quote_btn').value = 'saved';
}

function mailing_signup() {
	var name = $F($('mailing_signup_form')['name']);
	var email = $F($('mailing_signup_form')['email']);
	var birthday_month = $F($('mailing_signup_form')['birthday_month']);
	var birthday_day = $F($('mailing_signup_form')['birthday_day']);
	var birthday_year = $F($('mailing_signup_form')['birthday_year']);
	
	new Req.ajax({
		url: "/ajax/hottest_girl/mailing_signup",
		options: { parameters: "name=" + name + "&email=" + email + "&birthday_month=" + birthday_month + "&birthday_day=" + birthday_day + "&birthday_year=" + birthday_year }
	});

	return false;
}
