/* Namespaces */
if (!IE)
{
  var IE = {};
}

if (!IE.MUNSTEREXPRESS)
{
  IE.MUNSTEREXPRESS = {};
}

if (!IE.MUNSTEREXPRESS.CLASSIFIEDS)
{
  IE.MUNSTEREXPRESS.CLASSIFIEDS = {};
}

if (!IE.MUNSTEREXPRESS.CLASSIFIEDS.APP)
{
	IE.MUNSTEREXPRESS.CLASSIFIEDS.APP = {};
}

IE.MUNSTEREXPRESS.CLASSIFIEDS.APP = function(){
		
		return {
			// Precedes the search query with the ':site' and domain name keywords for google
			// to search correctly
			siteSearch: function(formObject)
			{
			    formObject.q.value= "site:" + location.host + " " + formObject.search_field.value
			}
			
		};	
}();


 $(document).ready(function() {
	
	$(".edit").editable("/advertiser/ajax_image_update",
    {
      indicator : "Saving...",
      tooltip : "Click to edit..."
    }
  );
	
	// start date picker
	$('#ad_starts_picker').datepicker(
			{
				mandatory: true, 
				dateFormat: 'yy-m-d',
				onSelect: function(datetext) {
					date = datetext.split('-')
					
					$('#ad_starts_1i option[value=' + date[0] + ']').attr("selected", "selected");
					$('#ad_starts_2i option[value=' + date[1] + ']').attr("selected", "selected");
					$('#ad_starts_3i option[value=' + date[2] + ']').attr("selected", "selected");
				}
			}
		);
	
	// end date picker
	$('#ad_ends_picker').datepicker(
			{
				mandatory: true,
				dateFormat:'yy-m-d',
				defaultDate: +7,
				onSelect: function(datetext) {
					date = datetext.split('-')
					
					$('#ad_ends_1i option[value=' + date[0] + ']').attr("selected", "selected");
					$('#ad_ends_2i option[value=' + date[1] + ']').attr("selected", "selected");
					$('#ad_ends_3i option[value=' + date[2] + ']').attr("selected", "selected");
				}
			}
		);
		
		$('#myAccordion').accordion(
			{
				header: 'a.header',
				autoHeight: false
			}
		);
		
		$('#search_form .labelover').labelOver('overlabel');
		
		$('.focus_me').focus();
		
		$('.limited').after('<p>Words left: <span class="word_counter"></span></p>');
		
		$('.limited').maxlength({
			'words': true,
			'feedback': '.word_counter',
			'hardLimit': true,
			'useInput': true
			
		});

		$('.toggle').toggle(
			function() {
				$('#content_sub_wrap').hide("fast", function(){
					$('body').attr("class", ""); 
				});	
				$(this).text('show sidebar');
			},
			function() {
				$('#content_sub_wrap').show("fast", function(){
					$('body').attr("class", "with_sub_content"); 
				});
				$(this).text('hide sidebar');
			}
		);

});
