

$(function(){
	$('.jqmWindow').jqm({toTop:true});
	
	$('.jqmTrigger').live('click',function(){
		var split = $(this).attr('id').split('_');
		$('#'+split[0]).jqmShow();
		return false;
	});
	
	$('#feedback').jqmAddTrigger('#navblock .contact_us');
	
	$('input#searchfield').focus(function(){
		$(this).val('');
	});
	
	$('input#searchfield').blur(function(){
		if($(this).val() == '')  $(this).val('Search Outlook commentary');
	});

	$('.jqmWindow input[name="cancel"], .jqmWindow .modal_close').live('click', function(){
		$(this).closest('.jqmWindow').jqmHide();
	});
	
	var feedback_hide_func = function(hash){
		hash.w.fadeOut('0',function(){  
			hash.o.remove(); 
			$('.jqmWindow .modalContent').find('p.success_message').remove();
			$('.jqmWindow .modalContent').find('form').resetForm().show();	
		});
			
	};
	$('#feedback').jqm({onHide: feedback_hide_func});
	
	var respond_hide_func = function(hash){
		hash.w.fadeOut('100',function(){ 
			hash.o.remove(); 
			$('.jqmWindow .modalContent').find('p.success_message').remove();
			$('.jqmWindow .modalContent').find('form').resetForm().find('input[type="hidden"]').remove();
			$('.jqmWindow .modalContent').find('form').show();
		});				
	 };
	 
	 $('#response').jqm({onHide: respond_hide_func});
	 
	 $('#nav li, #nav a.navstaticlink, #nav ul a, #nav #navselected, #nav a, #navselected a, #footer-wrapper a, #countrieslink a, #content .content_element').hover(
			 function(){ 	$(this).addClass('hover'); 		},
			 function(){ 	$(this).removeClass('hover');	}
	 );


	 /*$('#right_column .thumbnail_details').click(function(){
			window.location.href = $(this).find('a').attr('href');
	});*/
	 
	 $('#left_column a, #right_column .thumbnail_details, #footernav li').hover(
		function(){ $(this).addClass('hover'); },
		function(){ $(this).removeClass('hover'); }
	 );
	 
	 $(".activate_edit_mode").click(function(){
		 if(typeof(edit_initialized) == "undefined" || edit_initialized==false){
			 $.getScript("/lib/js/jquery-ui-sortable.js",function(){
				 $.getScript("/lib/js/editor.js");
			 });
		 }
		 $("body").toggleClass("editMode");
	 });
	 
	
		
});

function success_add_feedback(resp){	
	$('.jqmWindow').find('.modalContent').find('form').css('display','none').resetForm();
	if(resp.success == true)
		$('.jqmWindow .modalContent').append('<p id="' + resp.feedback_id + '" class="success_message">Thanks for sending your feedback with ID ' + resp.feedback_id + ' . You are going to be informed soon.</p>');
	else{
		if(resp.error_message.length > 0)	
			$('.jqmWindow .modalContent').append('<p>' + resp.error_message + '</p><p>Try again</p>');			
		else 
			$('.jqmWindow .modalContent').append('<p>Feedback send is failed!!!</p><p>Try again</p>');		
	}
	
	
}




