$(document).ready(function() {
/*
	$("#modal_open").fancybox({
		'overlayOpacity':0.7,
		'overlayColor':'#FFF',
		'overlayShow':true,
		'frameWidth':700,
		'frameHeight':450,
		'enableEscapeButton':true,
		'hideOnContentClick':false
	});	
*/	
});	


$('.story').click(function(){
	ajax_call('story_details.php','storyId=' + $(this).attr('storyId'), 'loadPage');						   
});

$('.story_button, .location_button').hover(function(){
		if($(this).attr('enabled')=="true"){											
			$(this).find("span").css('display','block').stop().animate({opacity:1}, 300);
		}
		
	},function(){
		if($(this).attr('enabled')=="true"){											
			$(this).find("span").stop().animate({opacity:0}, 300,"linear", function(){
				$(this).css('display','none');																				
			});
		}					
});

$('#previousButton, #nextButton').click(function(){	
	ajax_call('stories.php','pn=' + $(this).attr('pn') + '&cityId=' + $(this).attr('cityId'), 'loadPage');
});



$('.story_button').click(function(){
	ajax_call('story_details.php','storyId=' + $(this).attr('storyId'), 'loadPage');
});

$('.location_button').click(function(){
	ajax_call('location_details.php','storyId=' + $(this).attr('storyId') + '&locationId='+ $(this).attr('locationId'), 'loadPage');
});


function ajax_call(url, params, callback){
	$.ajax({
		type: "POST",
		url: url,
		cache: false,
		data: params,
		beforeSend:function() {
			$('#loading_indicator').css('display','block');
		},
		success: function(result){		
			$('#loading_indicator').css('display','none');
			eval(callback + "(result)");
		}
	});
}

function loadPage(data){
	$('#modal_container').stop().animate({opacity:0}, 200, "linear", function(){
		$('#modal_container').html(data);
		$('#modal_container').animate({opacity:1}, 200);
	});
}

function loadForm(data){
	$('#intro_right').stop().animate({opacity:0}, 200, "linear", function(){
		$('#intro_right').html(data);
		$('#intro_right').animate({opacity:1}, 200);
	});
}

function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		//limitCount.value = limitNum - limitField.value.length;
	}
}

function showStory(StoryId){	
	//alert('showing story');
	//$("#modal_open").attr('href','modal_container.php?url=story_details.php&params=storyId:' + StoryId);
	//$("#fancybox-overlay, #fancybox-wrap").css('display','block');
	//$("#modal_open").trigger('click');	
	//$("#modal_open").attr('href','modal_container.php?url=intro.php&params=name:');
	tb_show("",'modal_container.php?placeValuesBeforeTB_=savedValues&height=450&width=680&modal=true&url=story_details.php&params=storyId:' + StoryId,""); 
}

function showStories(CityId){	
	//alert('showing stories');
	//$("#modal_open").attr('href','modal_container.php?url=stories.php&params=cityId:' + CityId);
	//$("#fancybox-overlay, #fancybox-wrap").css('display','block');
	//$("#modal_open").trigger('click');			
	//$("#modal_open").attr('href','modal_container.php?url=intro.php&params=name:');
	tb_show("",'modal_container.php?placeValuesBeforeTB_=savedValues&height=450&width=680&modal=true&url=stories.php&params=cityId:' + CityId,""); 
}
