/* GYT EVENTS

   Gyorgytea.hu - All rights reserved/Minden jog fenntartva.
   gyt.events.js
*/

var eventDetails = new Array(); //to store event information in

$(document).ready(function() { 
		
		$('.event').gytEvents();
		
});

/* Get URl Vars */
function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}

/* Redirect if hash address is loaded */
if(window.location.hash!=='' && (typeof(getUrlVars()['n'])!=='undefined') && (typeof(getUrlVars()['i'])!=='undefined'))
{
	var url = window.location.hash.replace('#!', '');
	url = base_url + url;
	window.location = url;
}


//Gyt Events Plugin
(function($){
 
    $.fn.extend({
         
        gytEvents: function() {
        
        	//Mouseover
        	$(this).mouseenter(function(){
        		$(this).find('.event-services .tanacsadas').css('opacity',1.0); 
        		$(this).find('.event-services .eloadas').css('opacity',1.0);
        		$(this).find('.event-services .arusitas').css('opacity',1.0);
        	});
 			$(this).mouseleave(function(){
 				$(this).find('.event-services .tanacsadas').css('opacity',0.5); 
        		$(this).find('.event-services .eloadas').css('opacity',0.5);
        		$(this).find('.event-services .arusitas').css('opacity',0.5);
 			});
 
            //Iterate over the current set of matched elements
            var _this = this;
            return _this.each(function() {
             
             	//attach click 
             	$(this).click(function(){
             		var e_id = $(this).attr('rel');			//event identifier
             		var e_det = eventDetails[e_id];
             		$('.event-detailed-'+e_id).blackBox(); 	//open blackbox
					options = 
					{
						latitude:               e_det.event_lat,
						longitude:              e_det.event_lng,
						zoom:                   15,
						controls:               ["GSmallZoomControl3D"],
						scrollwheel:            true,
						maptype:                G_NORMAL_MAP,
						markers:				[{latitude: e_det.event_lat, longitude: e_det.event_lng, html: e_det.event_address}]
					};
					$(".blackbox .event-map").gMap(options); //init map
					window.location.hash = '!/rendezvenyek/?n='+e_det.event_escaped_name+'&i='+e_id;//add hash to url
				});
				
				//attach click to href-s
				var _element = this;
				$(this).find('a').click(function(){
					$(_element).click();
					return false;
				});
		
            });
        }
    });
           
})(jQuery);
