

var	TrendGal={
	init:function(){
		TrendGal.Util.setBaseUrl();
		TrendGal.UI.init();	
		$('#tabs').tabs();	
		$('#social_tabs').tabs({unselected:true, fx: { height: 'toggle' }});	
		$('.drop_navigation').dropNav();
		if (typeof(jQuery.fn.autocomplete)!=="undefined") {
			$('#UserCity').autocomplete(TrendGal.Util.url('/cities/autocomplete/'),{minChars:3});					
		};
	},
	UI:{
		init:function(){
			$('select#UserCountry').each(function(){
				TrendGal.UI.populateRegions(this.options[this.selectedIndex].value);
			});			
			$('select#UserCountry').change(function(){
				TrendGal.UI.populateRegions(this.options[this.selectedIndex].value);
			});
		},
		populateRegions:function(countryId){
			// countryId-=1;
			var url= TrendGal.Util.url('/regions/listRegions/'+countryId);
			var div= $('#UserRegionId')[0].parentNode;
			$(div).load(url);
		}
	},
	Util:{
		setBaseUrl: function(url){
		    TrendGal.baseUrl = url || $('script[@src$=js/common.js]')
		        .attr('src')
		        .replace(/js\/common.js$/,'');
		}, 
		url: function(url){
		    return TrendGal.baseUrl+url.replace(/^\/+/, '');
		}
	}

}


var Common =
{
    baseUrl: null, setBaseUrl: function(url)
    {
        Common.baseUrl = url || $('script[@src$=js/common.js]')
            .attr('src')
            .replace(/js\/common.js$/,'');
    }, url: function(url)
    {
        return this.baseUrl+url.replace(/^\/+/, '');
    }
}
 

$(document).ready(function(){
	TrendGal.init();
	$('.input .validate').validateOverCake();
});



