jQuery(document).ready(function(){
  
  jQuery('li.pdf a').click(function(){
    pageTracker._trackPageview('/letoltes/teljes_katalogus');
  });
  
  var back_res = null;
  jQuery.each(background_sizes, function(key, size){
	try{
	  if(size >= screen.width && background_sizes[key + 1] >= screen.width && back_res == null){
		back_res = size;
	  }
	}catch(err){
	  
	}
  });
  
  if(back_res == null){
	back_res = background_sizes[background_sizes.length - 1];
  }
  
  jQuery('.bg_change').addClass('background_' + back_res);
  
  if(jQuery('body').height() < jQuery(document).height()){
	jQuery('body').height((jQuery(document).height() + 200) + 'px');
  }
  
  jQuery(window).resize(function(){
	resize_event();
  });///handle resize event
  
  jQuery('div.wp-caption.alignleft img.tabbed').each(function(){
    jQuery(this).parents('div').addClass('tabbed');
  });
  
  jQuery('div.wp-caption.alignright img.tabbed').each(function(){
    jQuery(this).parents('div').addClass('tabbed');
  });
  
  jQuery('div.wp-caption.alignleft img.stabbed').each(function(){
    jQuery(this).parents('div').addClass('stabbed');
  });
  
  jQuery('div.wp-caption.alignright img.stabbed').each(function(){
    jQuery(this).parents('div').addClass('stabbed');
  });
  
  jQuery('div.wp-caption.aligncenter img.between').each(function(){
    jQuery(this).parents('div').addClass('between');
  });
  /////////////////
  ///slider
  /////////////////
  var next_index = null;
  
  jQuery('.next').click(function(event){
	
	max = jQuery('.navigation .next').size();
	next_index_poss = max - jQuery('#' + event.currentTarget.id).index() - 1;
	
	if(next_index == next_index_poss){
	  return;
	}else{
	  next_index = next_index_poss;
	}
	
	jQuery('.next').removeClass('active');
	jQuery('#' + event.currentTarget.id).addClass('active');
	
	jQuery('.slide:eq(' + next_index + ')').addClass('next');
	jQuery('.slide.next').css({'left' : '750px'})
	jQuery('.slide.active, .slide.next').animate({"left": "-=750px"}, "slow", function(){
	  
	  jQuery('.slide.active').removeClass('active');
	  jQuery('.slide.next').removeClass('next');
	  jQuery('.slide:eq(' + next_index + ')').addClass('active');
	  
	});
	
  });
  
  jQuery('.slide').each(function(){
	var link = jQuery(this).children('.slide_rel').children('.navigation_back').children('h2').children('a').attr('href');
	jQuery(this).click(function(){
	  location.href = link;
	});
  })
  
  /////////////////
  ///slider
  /////////////////
  
  jQuery('.switch li img').click(function(){
	
  });
  
  jQuery('.news_item .product_property').each(function(){
	var current_link = jQuery(this).children('a').attr('href');
	jQuery(this).parent('.news_item').click(function(){
	  location.href = current_link;
	});
  });
  
  jQuery('.product_taxonomy h2').each(function(){
	var current_link = jQuery(this).children('a').attr('href');
	jQuery(this).parent('.product_taxonomy').click(function(){
	  location.href = current_link;
	});
  });
  
  jQuery('.current-menu-item').each(function(){
	jQuery(this).parent('ul').css({display: 'block'});
	jQuery(this).children('ul').css({display: 'block'});
	resize_event();
  }); 
  
  jQuery('.staff_members .staff_member').each(function(){
	jQuery(this).hide();
  });
  
  jQuery('.staff_members .staff_member:eq(0)').show();
  
  jQuery('#potential_objects').change(function(){
	var current_staff_index = jQuery("#potential_objects :selected").index();
	jQuery('.staff_members .staff_member').each(function(){
	  jQuery(this).hide();
	});
	current_staff_index = current_staff_index - 1;
	if(current_staff_index < 0) current_staff_index = 0;
	jQuery('.staff_members .staff_member:eq(' + current_staff_index + ')').show();
	jQuery('#mailto').val(jQuery('.staff_members .staff_member:eq(' + current_staff_index + ')').children('.mailto').html());
  });
  
  fix_flash();
  
  jQuery('#megye_selector, #partner_selector').change(function() {
	if(this.value != 'null') location.href = this.value;
  });
  
  jQuery('.partner button').click(function(){
	location.href = jQuery(this).parent('div').children('input').attr('value');
  });
  
  jQuery('.newslink').each(function(){
	var url = jQuery(this).attr('href');
	jQuery(this).parents('.post').click(function(){
	  location.href = url;
	});
  });
  
  initialize_single_partner_map();
  
});

function resize_event(){
  //var page_height = jQuery(document).height();
  var page_width = jQuery(document).width();
  
  jQuery('.bg_opaque').css({'height' : "100%", 'width' : page_width + "px"});
}//////resize_event


function fix_flash() {
    // loop through every embed tag on the site
    var embeds = document.getElementsByTagName('embed');
    for (i = 0; i < embeds.length; i++) {
        embed = embeds[i];
        var new_embed;
        // everything but Firefox & Konqueror
        if (embed.outerHTML) {
            var html = embed.outerHTML;
            // replace an existing wmode parameter
            if (html.match(/wmode\s*=\s*('|")[a-zA-Z]+('|")/i))
                new_embed = html.replace(/wmode\s*=\s*('|")window('|")/i, "wmode='transparent'");
            // add a new wmode parameter
            else
                new_embed = html.replace(/<embed\s/i, "<embed wmode='transparent' ");
            // replace the old embed object with the fixed version
            embed.insertAdjacentHTML('beforeBegin', new_embed);
            embed.parentNode.removeChild(embed);
        } else {
            // cloneNode is buggy in some versions of Safari & Opera, but works fine in FF
            new_embed = embed.cloneNode(true);
            if (!new_embed.getAttribute('wmode') || new_embed.getAttribute('wmode').toLowerCase() == 'window')
                new_embed.setAttribute('wmode', 'transparent');
            embed.parentNode.replaceChild(new_embed, embed);
        }
    }
    // loop through every object tag on the site
    var objects = document.getElementsByTagName('object');
    for (i = 0; i < objects.length; i++) {
        object = objects[i];
        var new_object;
        // object is an IE specific tag so we can use outerHTML here
        if (object.outerHTML) {
            var html = object.outerHTML;
            // replace an existing wmode parameter
            if (html.match(/<param\s+name\s*=\s*('|")wmode('|")\s+value\s*=\s*('|")[a-zA-Z]+('|")\s*\/?\>/i))
                new_object = html.replace(/<param\s+name\s*=\s*('|")wmode('|")\s+value\s*=\s*('|")window('|")\s*\/?\>/i, "<param name='wmode' value='transparent' />");
            // add a new wmode parameter
            else
                new_object = html.replace(/<\/object\>/i, "<param name='wmode' value='transparent' />\n</object>");
            // loop through each of the param tags
            var children = object.childNodes;
            for (j = 0; j < children.length; j++) {
                try {
                    if (children[j] != null) {
                        var theName = children[j].getAttribute('name');
                        if (theName != null && theName.match(/flashvars/i)) {
                            new_object = new_object.replace(/<param\s+name\s*=\s*('|")flashvars('|")\s+value\s*=\s*('|")[^'"]*('|")\s*\/?\>/i, "<param name='flashvars' value='" + children[j].getAttribute('value') + "' />");
                        }
                    }
                }
                catch (err) {
                }
            }
            // replace the old embed object with the fixed versiony
            object.insertAdjacentHTML('beforeBegin', new_object);
            object.parentNode.removeChild(object);
        }
    }
    
    resize_event();
    
}





function initialize_single_partner_map() {
  
  var geocoder;
  var map;
  
  geocoder = new google.maps.Geocoder();
  var latlng = new google.maps.LatLng(47.30, 19.05);
  var myOptions = {
	zoom: 8,
	center: latlng,
	mapTypeId: google.maps.MapTypeId.ROADMAP
  }
  map = new google.maps.Map(document.getElementById("single_map"), myOptions);
  
  /////geocoding address
  var address = document.getElementById("hidden_address").value;
  geocoder.geocode( {'address': address}, function(results, status) {
	if (status == google.maps.GeocoderStatus.OK) {
	  map.setCenter(results[0].geometry.location);
	  var marker = new google.maps.Marker({
		  map: map, 
		  position: results[0].geometry.location
	  });
	} else {
	  //alert("Geocode was not successful for the following reason: " + status);
	}
  });
  /////geocoding address
  
}//////initialize_single_partner_map
