var Site = {

	ec: function() {

		if(jQuery('#content .col1').length && jQuery('#content .col2').length) {

			var height1 = jQuery('#content .col1').height();
			var height2 = jQuery('#content .col2').height();
			if(height1 > height2) jQuery('#content .col2').css({height:height1+'px'});

		}

	},

	em: function() {

		document.write('<a href=\'&#109;ailto&#58;&#105;&#110;f&#111;%4&#48;%7&#54;s%&#55;5&#46;&#37;6&#50;e\'>i&#110;fo&#64;vsu&#46;&#98;&#101;</a>');

	},

	fHeader: function() {

		if(jQuery(window).width()<1200) {
			jQuery('#top').css({position:'relative',width:'1200px'});
			jQuery('#top-dummy').hide();
		} else {
			jQuery('#top').css({position:'fixed',width:'100%'});
			jQuery('#top-dummy').show();
		}

	},

	fGetClass: function(o) {

		var c = jQuery(o).parent().parent().parent().parent().parent().attr('class');

		if(c != 'undefined') {

			c = c.split(' ');
			c = (c.length == 2) ? c[1] : '';

		} else c = '';

		return c;

	},

	fGetResult: function(f) {

		// set some vars
		var data = [];
		var location = Site.fGetClass(f);
		if(location != 'top') location = 'bottom';
		data.push('action=getMembers');
		data.push('q='+encodeURIComponent(jQuery('#member-list .toolbar.'+location+' input[name="q"]').attr('value')));
		data.push('p='+jQuery('#member-list .toolbar.'+location+' select[name="p"]').attr('value'));
		data.push('pr='+jQuery('#member-list .toolbar.'+location+' select[name="pr"]').attr('value'));
		data.push('s='+jQuery('#member-list .toolbar.'+location+' select[name="s"]').attr('value'));

		// ajax
		jQuery.get(Members.ajax, data.join('&'), function(html){jQuery('#member-list').html(html)});

		// scroll to top
		if(location == 'bottom') scrollTo(0, 220);

	},

	gcf: function(parent) {

		// define parent id
		var parent_id = parent.attr('class');
		parent_id = parent_id.replace(/\D/g,'');

		if(parent_id) {

			jQuery.get(
				'/assets/bin/services.php',
				{a:'gcf',p:parent_id},
				function(html) {

					// append html
					parent.append(html);

					// autoselect first field
					jQuery('input[type="text"]:first',parent).select();

				}
			);

		}

	},

	gmMember: function() {

		var script = document.createElement('script');
		script.type = 'text/javascript';
		script.src = 'http://maps.googleapis.com/maps/api/js?sensor=false&callback=Site.gmMemberInit';
		document.body.appendChild(script);

	},

	gmMemberInit: function() {

		jQuery.each(Member.address, function(index, value){

			var geocoder = new google.maps.Geocoder();
			var myOptions = {zoom:15,mapTypeId:google.maps.MapTypeId.ROADMAP}
			var map = new google.maps.Map(document.getElementById('gm-'+index), myOptions);

			geocoder.geocode({address:value}, function(results, status) {

				if(status == google.maps.GeocoderStatus.OK) {

					map.setCenter(results[0].geometry.location);
					var marker = new google.maps.Marker({position:results[0].geometry.location,map:map,title:value});

				}

			});

		});

	},

	initFilter: function() {

		// set some binds
		jQuery('#member-list .toolbar a').live('click', function(){

			jQuery('#member-list .toolbar select[name="p"]').attr('value', jQuery(this).attr('rel'));
			Site.fGetResult(this);
			return false;

		});
		jQuery('#member-list .toolbar button').live('click', function(){Site.fGetResult(this)});
		jQuery('#member-list .toolbar input[name="q"]').live('keyup', function(e){if(e.which == 13)Site.fGetResult(this)});
		jQuery('#member-list .toolbar select').live('change', function(){Site.fGetResult(this)});

	},

	ti: function(id,q,s) {

	    if(q=='focus') { if(jQuery.trim(jQuery(id).val())==s) jQuery(id).attr('value',''); }
	    else { if(jQuery.trim(jQuery(id).val())=='') jQuery(id).attr('value',s); }

	}

};

// execute some scripts when document is loaded
jQuery(document).ready(function(){

	// equalize cols
	setTimeout("Site.ec()", 300);

	// menu top
	jQuery('#top li.sub').mouseover(function(){jQuery(this).addClass('hover').find('ul').show();});
	jQuery('#top li.sub').mouseout(function(){jQuery(this).removeClass('hover').find('ul').hide();});
	jQuery(window).resize(function(){Site.fHeader()})
	Site.fHeader();

	// slideshow home
	if(jQuery('#home-intro').length) {

		jQuery('#home-intro .banner ul').bxSlider({auto:true,controls:false,mode:'fade',pause:5000,speed:1000});

	}

	// search - bind events
	jQuery('form[name="search"] input[name="q"]').bind('focus',function(){Site.ti('form[name="search"] input[name="q"]', 'focus', LNG.defaultKeyword);});
	jQuery('form[name="search"] input[name="q"]').bind('blur',function(){Site.ti('form[name="search"] input[name="q"]', 'blur', LNG.defaultKeyword);});

	// newsletter - bind events
	jQuery('form[name="newsletter"] input[name="email"]').bind('focus',function(){Site.ti('form[name="newsletter"] input[name="email"]', 'focus', LNG.defaultNewsletter);});
	jQuery('form[name="newsletter"] input[name="email"]').bind('blur',function(){Site.ti('form[name="newsletter"] input[name="email"]', 'blur', LNG.defaultNewsletter);});

	// google maps
	if(jQuery('div[id^="gm"]').length && Member.address != undefined) Site.gmMember();

	// members - filter
	if(jQuery('#member-list .toolbar').length) Site.initFilter();

	// autocomplete
	jQuery('input[name="q"]').autocomplete({
		source:'/assets/bin/services.php?action=search&language='+LNG.language,
		minLength:2,
		select: function(event, ui) {
			if(ui.item) jQuery(this).attr('value', ui.item.value).parent().parent().parent().parent().parent().submit();
		}
	});

	// blog - bind event for comments
	jQuery('.react div').click(function() {

		// empty value
		jQuery(this).html('');

		// only proceed when we don't have a form yet in our parent
		var parent = jQuery(this).parent().parent();
		if(!jQuery('form',parent).length) Site.gcf(parent);

		// remove button
		jQuery(this).parent().remove();

	});

	// back to top
	jQuery('a[href="#top"]').click(function(){jQuery(window).scrollTop(0)});

});
