function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

$(function() {
	
	var oldrowclass;
	var rstd;
	
	$('.row1, .row2').click(function() {
		var obj = $(this).find('td:last').children().attr('href');
		if (obj) {
			document.location.href = obj;
		}
	});
	
	
	$('.row1, .row2').mouseover(function() {
		oldrowclass = $(this).attr("class");
		oldrowclass = jQuery.trim(oldrowclass);
		var sclasses = oldrowclass.split(" "); 
		$(this).removeClass(oldrowclass);
		$(this).addClass('row_active');
		rstd = '.' + sclasses[1] + '_rs';
		$(rstd).addClass('row_active');
		$(this).css("cursor", "pointer");
	});
	
	$('.row1, .row2').mouseout(function() {
		oldrowclass = jQuery.trim(oldrowclass)
		$(this).removeClass('row_active');
		$(this).addClass(oldrowclass);
		$(rstd).removeClass('row_active');
	});
	
	//Hide the submenus, accordion for the SIDEBAR.
	
	$('#navigation ul li ul').hide();
	$("#navigation ul li:has(ul)").addClass("theDon");
	$("#navigation ul li ul li:has(a)").addClass("henchmen");
	$('#navigation .theDon > a').attr('href', '#');
	
	$('.current_page_parent').mouseover(function() {
		$("#menu").children().each(function() {
  		if (!$(this).hasClass('current_page_parent')) {
  				$(this).find("ul").slideUp('normal');
  		}
  	});
	});
	
	
	$('#navigation > ul > li > a').mouseover(function () {
		var checkElement = $(this).next();
    if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
    	$("#menu").children().each(function() {
  			if (!$(this).hasClass('current_page_parent') && checkElement.is('ul') && (!checkElement.is(':visible'))) {
  					$(this).find("ul").slideUp('normal');
  			}
  		});
    	return false;
    }
		if((checkElement.is('ul')) && (!checkElement.is(':visible'))   ) {
			if ($(this).parent().hasClass('current_page_parent:not')) {
				$('#menu ul:visible').slideUp('normal');
			}
			
			$("#menu").children().each(function() {
  			if (!$(this).hasClass('current_page_parent')) {
  					$(this).find("ul").slideUp('normal');
  			}
  		});
			checkElement.slideDown('normal');
			return false;                    
    }
    
    $("#menu").children().each(function() {
  		if (!$(this).hasClass('current_page_parent')) {
  				$(this).find("ul").slideUp('normal');
  		}
  	});
    
    
    
  });
  
  
  
  $('#homeflash, .wide, .post, #logo').mouseover(function() {
  	$("#menu").children().each(function() {
  		if (!$(this).hasClass('current_page_parent')) {
  				$(this).find("ul").slideUp('normal');
  		}
  	});
  });
	
	var pathname = window.location.href;
	//console.debug(pathname);
	
	if (pathname.indexOf('lakasok') != -1 || pathname.indexOf('apartment?') != -1) {
		
		if (jslang == 'hu') {
			$('.page-item-15').addClass('current_page_ancestor');
			$('.page-item-15').addClass('current_page_parent');
			$('.page-item-17').addClass('current_page_item');
		} else {
			
			$('.page-item-391').addClass('current_page_ancestor');
			$('.page-item-391').addClass('current_page_parent');
			$('.page-item-393').addClass('current_page_item');
		}
		
		var lakasokarr = gup('f');
		
		var lakas = lakasokarr.split('-');
		switch(lakas[0]) {
				case 'a1':
					flashvars = {wmode: 'opaque', singleimage: '/wp-content/themes/pasaretresidence/images/backgrounds/tavasz.jpg'};
					attributes = {wmode: 'opaque' , singleimage: '/wp-content/themes/pasaretresidence/images/backgrounds/tavasz.jpg'};
					params = {wmode: 'opaque' , singleimage: '/wp-content/themes/pasaretresidence/images/backgrounds/tavasz.jpg'};
					swfobject.embedSWF("/wp-content/themes/pasaretresidence/flash/home.swf?rand=" + rand[0], "homeflash", "550", "400", "8.0.0", flashvars, params, attributes);
				  break;
				case 'a2':
				  flashvars = {wmode: 'opaque', singleimage: '/wp-content/themes/pasaretresidence/images/backgrounds/nyar.jpg'};
					attributes = {wmode: 'opaque' , singleimage: '/wp-content/themes/pasaretresidence/images/backgrounds/nyar.jpg'};
					params = {wmode: 'opaque' , singleimage: '/wp-content/themes/pasaretresidence/images/backgrounds/nyar.jpg'};
				  swfobject.embedSWF("/wp-content/themes/pasaretresidence/flash/home.swf?rand=" + rand[1], "homeflash", "550", "400", "8.0.0", flashvars, params, attributes);
				  break;
				case 'b1':
				  flashvars = {wmode: 'opaque', singleimage: '/wp-content/themes/pasaretresidence/images/backgrounds/osz.jpg'};
					attributes = {wmode: 'opaque' , singleimage: '/wp-content/themes/pasaretresidence/images/backgrounds/osz.jpg'};
					params = {wmode: 'opaque' , singleimage: '/wp-content/themes/pasaretresidence/images/backgrounds/osz.jpg'};
				  swfobject.embedSWF("/wp-content/themes/pasaretresidence/flash/home.swf?rand=" + rand[2], "homeflash", "550", "400", "8.0.0", flashvars, params, attributes);
				  break;
				case 'b2':
				  flashvars = {wmode: 'opaque', singleimage: '/wp-content/themes/pasaretresidence/images/backgrounds/tel.jpg'};
					attributes = {wmode: 'opaque' , singleimage: '/wp-content/themes/pasaretresidence/images/backgrounds/tel.jpg'};
					params = {wmode: 'opaque' , singleimage: '/wp-content/themes/pasaretresidence/images/backgrounds/tel.jpg'};
				  swfobject.embedSWF("/wp-content/themes/pasaretresidence/flash/home.swf?rand=" + rand[3], "homeflash", "550", "400", "8.0.0", flashvars, params, attributes);
				  break;
				default:
				  break;
			}
		
	}
	
	if (pathname.indexOf('uzletek') != -1) {
		$('.page-item-47').addClass('current_page_item');
	}
	
	if (pathname.indexOf('shop?') != -1) {
		$('.page-item-417').addClass('current_page_item');
	}
	
	
	if ($('#navigation ul li').hasClass("current_page_parent")) {
		//$('#navigation .current_page_parent ul').addClass("displayMe"); 
		$('#navigation .current_page_parent ul').css({'display':'block'}); 
	}
	
	
	/******** TABS ************/
	$(".tab:not(:first)").hide();
	
	$(".tab:first").show(function() {
		var par = $('.htabs li:first');
		current_tab_arrow (par);
	});
	
	
	$(".htabs a, .htabsflats a").click(function() { //when we click one of the tabs
		
		if ($('.htabs').length > 0) { 
			var childs = $('.htabs').children();
				for (i=0; i < childs.length; i++) {
					child_class = $(childs[i]).attr('class');
					if (child_class.indexOf('active') != -1) {
						$(childs[i]).removeClass('active');
					}
			}
		}
		
		
		
		/* Positioning the element */
		var par = $(this).parent();
		current_tab_arrow (par);
		
 		stringref = $(this).attr("href").split('#')[1]; //get the ID of the element we need to show
 		$('.tab:not(#'+stringref+')').hide(); //hide the tabs that doesn't match the ID
 		if ($.browser.msie && $.browser.version.substr(0,3) == "6.0") { //fix
				$('.tab#' + stringref).show();
 		} else {
 			//display our tab fading it in
 			$('.tab#' + stringref).fadeIn();
 		}
 		//stay with me
 		return false;
 	});
		
  
  
	
	function current_tab_arrow (par) {
		if ($('#current_tab').length > 0) {
			var pos =  par.position();
			par.addClass('active');
			var w = par.width() / 2;
			$('#current_tab').css('display','none');
			$('#current_tab').css('left' , pos.left + w - 4);
			$('#current_tab').css('top' , pos.top + 30);
			$('#current_tab').css('display','block');
		} else if ($('.htabsflats').length > 0) {
			var childs = $('.htabsflats').children();
			for (i=0; i < childs.length; i++) {
				child_class = $(childs[i]).attr('class');
				if (child_class.indexOf('_current_flat') != -1) {
					$(childs[i]).removeClass(child_class);
					$(childs[i]).addClass(child_class.substr(1,3));
				}
				
			}
			if (par.length == 0) {
				par = $('.A1');
			}
			old_class = par.attr('class');
			new_class = par.attr('class') + '_current_flat';	
			par.removeClass(old_class);
			par.addClass(new_class);
			
			
			/*
			flashvars = {wmode: 'opaque', singleimage: '/wp-content/themes/pasaretresidence/images/backgrounds/tavasz.jpg'};
			attributes = {wmode: 'opaque' , singleimage: '/wp-content/themes/pasaretresidence/images/backgrounds/tavasz.jpg'};
			params = {wmode: 'opaque' , singleimage: '/wp-content/themes/pasaretresidence/images/backgrounds/tavasz.jpg'};
			swfobject.embedSWF("/wp-content/themes/pasaretresidence/flash/home.swf?rand=" + rand[0], "homeflash", "550", "400", "8.0.0", flashvars, params, attributes);
			*/

			swfobject.removeSWF('homeflash');
			//$('<div id="homeflash_generated"></div>').appendTo('#flashcont');
			$('<div id="homeflash"></div>').appendTo('#flashcont');
			
			switch($.trim(old_class)) {
				case 'A1':
					flashvars = {wmode: 'opaque', singleimage: '/wp-content/themes/pasaretresidence/images/backgrounds/tavasz.jpg'};
					attributes = {wmode: 'opaque' , singleimage: '/wp-content/themes/pasaretresidence/images/backgrounds/tavasz.jpg'};
					params = {wmode: 'opaque' , singleimage: '/wp-content/themes/pasaretresidence/images/backgrounds/tavasz.jpg'};
					swfobject.embedSWF("/wp-content/themes/pasaretresidence/flash/home.swf?rand=" + rand[0], "homeflash", "550", "400", "8.0.0", flashvars, params, attributes);
				  newresize();
				  break;
				case 'A2':
				  flashvars = {wmode: 'opaque', singleimage: '/wp-content/themes/pasaretresidence/images/backgrounds/nyar.jpg'};
					attributes = {wmode: 'opaque' , singleimage: '/wp-content/themes/pasaretresidence/images/backgrounds/nyar.jpg'};
					params = {wmode: 'opaque' , singleimage: '/wp-content/themes/pasaretresidence/images/backgrounds/nyar.jpg'};
				  swfobject.embedSWF("/wp-content/themes/pasaretresidence/flash/home.swf?rand=" + rand[1], "homeflash", "550", "400", "8.0.0", flashvars, params, attributes);
				  newresize();
				  break;
				case 'B1':
				  flashvars = {wmode: 'opaque', singleimage: '/wp-content/themes/pasaretresidence/images/backgrounds/osz.jpg'};
					attributes = {wmode: 'opaque' , singleimage: '/wp-content/themes/pasaretresidence/images/backgrounds/osz.jpg'};
					params = {wmode: 'opaque' , singleimage: '/wp-content/themes/pasaretresidence/images/backgrounds/osz.jpg'};
				  swfobject.embedSWF("/wp-content/themes/pasaretresidence/flash/home.swf?rand=" + rand[2], "homeflash", "550", "400", "8.0.0", flashvars, params, attributes);
				  newresize();
				  break;
				case 'B2':
				  flashvars = {wmode: 'opaque', singleimage: '/wp-content/themes/pasaretresidence/images/backgrounds/tel.jpg'};
					attributes = {wmode: 'opaque' , singleimage: '/wp-content/themes/pasaretresidence/images/backgrounds/tel.jpg'};
					params = {wmode: 'opaque' , singleimage: '/wp-content/themes/pasaretresidence/images/backgrounds/tel.jpg'};
				  swfobject.embedSWF("/wp-content/themes/pasaretresidence/flash/home.swf?rand=" + rand[3], "homeflash", "550", "400", "8.0.0", flashvars, params, attributes);
				  newresize();
				  break;
				default:
				  break;
			}
		}
	}
	
	function newresize() {
		w = $(window);
		W = w.width();
		H = w.height();
		$('#wrapper').width(W - 30);
		$('#wrapper').height(H - 30);
		swffit.fit('homeflash', 1170, 670, W - 30, H - 30, true, true);
	}
	
	
	if (jslang == 'hu') {
		$("a[rel^='prettyPhoto']").prettyPhoto({
				opacity: 0.40,
				theme: 'dark_square',
				overlay_gallery: false
		});
	} else {
		$("a[rel^='prettyPhoto']").prettyPhoto({
				opacity: 0.40,
				theme: 'light_square',
				overlay_gallery: false
		});
	}
});


