$(document).ready(function() {

    projectPath = projectPath + '/';


    Cufon.replace('#selectBoxHeader, h2 ,h3', {fontFamily: 'Miso',hover: true});

    /* view object contains all manipulation functions for the view (animations,data getting/setting) but no logic*/
    var hoverColor = "#004b7e";

    view = {
        init : function() {

            $('#selectBoxHeader').click(function() {

                $('#topDropDown').slideToggle("fast");

                $('#topDropDown').mouseleave(function() {
                    $(this).slideUp("fast");
                });
            });

            view.createHoverEffect(".boxLink",hoverColor);
        },
        createHoverEffect : function(selector,hoverColor) {

            var initialBackgroundColor = $(selector).css("backgroundColor");

            $(selector).hover(function() {
               $(this).animate({
                   backgroundColor:hoverColor
               }, 200);
            },function() {
               $(this).animate({
                   backgroundColor:initialBackgroundColor
               }, 200);
            });

        }

    };

    view.init();

    checkEmptyField("textSearch");
    
    
    
    /* Dropdown links */
    $('.eventCategoryDropdown').change(function(){;
        if ($('.eventCategoryDropdown').val() != '') {
            var locationId = '?eventcategory='+$('.eventCategoryDropdown').val()+'&mycity='+mycity;
        } else {
            var locationId = '?mycity='+mycity;
        }
        window.location = projectPath+'pages/event/view/event_list.php'+locationId;
    });
    $('#event_archive_list_container .eventCategoryDropdown').change(function(){;
    if ($('.eventCategoryDropdown').val() != '') {
    	var locationId = '?eventcategory='+$('.eventCategoryDropdown').val()+'&mycity='+mycity;
    } else {
    	var locationId = '?mycity='+mycity;
    }
    window.location = projectPath+'pages/event/view/event_archive.php'+locationId;
    });
    
    $('.interpretCategoryDropdown').change(function(){;
	    if ($('.interpretCategoryDropdown').val() != '') {
	        var locationId = '?interpretcategory='+$('.interpretCategoryDropdown').val()+'&mycity='+mycity;
	    } else {
	    	var locationId = '?mycity='+mycity;
	    }
	    window.location = projectPath+'pages/interpret/view/interpret_list.php'+locationId;
	});
    
    $('.locationCategoryDropdown').change(function(){;
        if ($('.locationCategoryDropdown').val() != '') {
            var locationId = '?locationcategory='+$('.locationCategoryDropdown').val()+'&mycity='+mycity;
        } else {
            var locationId = '?mycity='+mycity;
        }
        window.location = projectPath+'pages/location/view/location_list.php'+locationId;
    });

    $('.smalladCategoryDropdown').change(function(){;
        if ($('.smalladCategoryDropdown').val() != '') {
            var locationId = '?smalladcategory='+$('.smalladCategoryDropdown').val()+'&mycity='+mycity;
        } else {
            var locationId = '?mycity='+mycity;
        }
        window.location = projectPath+'pages/smallad/view/smallad_list.php'+locationId;
    });

    $('.galleryDropdown').change(function(){;
        if ($('.galleryDropdown').val() != '') {
            var locationId = '?gallery='+$('.galleryDropdown').val()+'&mycity='+mycity;
        } else {
            var locationId = '?mycity='+mycity;
        }
        window.location = projectPath+'pages/galleryimage/view/galleryimage_form.php'+locationId;
    });


    /* Datepicker */

	  $(".editDate").datepicker();
	  $(".editDate").datepicker($.datepicker.regional['rs']);

	  $(".editDate").datepicker( "option", "autoSize", true );
	  $(".editDate").datepicker( "option", "showOn", "both" );
	  $(".editDate").datepicker( "option", "buttonImage", "/img/dateIcon.png" );
	  $(".editDate").datepicker( "option", "closeText", 'closeme' );

    /* Autocomplete */
          var timeData = "01:00 01:30 02:00 02:30 03:00 03:30 04:00 04:30 05:00 05:30 06:00 06:30 07:00 07:30 08:00 08:30 09:00 09:30 10:00 10:30 11:00 11:30 12:00 12:30 13:00 13:30 14:00 14:30 15:00 15:30 16:00 16:30 17:00 17:30 18:00 18:30 19:00 19:30 20:00 20:30 21:00 21:30 22:00 22:30 23:00 23:30 ".split(" ");
          $('#event_starttime').autocomplete(timeData);
          $('#event_endtime').autocomplete(timeData);
          $('#news_time').autocomplete(timeData);

 
});

function checkEmptyField (id){
	var obj = $("#"+id);
	if (obj.val()==''){
    	obj.val(obj.attr('title'));
    }
	obj.click(function(){
		if (obj.val() == obj.attr('title')){
			obj.val('');
		}
    });
	obj.blur(function(){
    	checkEmptyField(id);
    });
}