$(document).ready(function(){
  // header menü
  $('#mainMenuContainer li.rootVoice').mouseover(function(){
    $('#'+this.id+'_submenu').show();
  });
  $('#mainMenuContainer li.rootVoice').mouseout(function(){
    $('#'+this.id+'_submenu').hide();
  });

  // random akcio
  $('#randomAkcioContainer a.akcioLink strong').each(function (){
    var fontSize = 24;
    var minFontSize = 11;
    
    while($(this).height()>30 && fontSize>minFontSize)
      {
        fontSize = fontSize - 2;
        $(this).css("font-size",fontSize+"px");
      }
    $(this).css("height","30px");
  });

  $('#randomAkcioContainer').cycle({
    fx: 'scrollDown',
    pause:  1,
    speed: 1000,
    timeout: 2000,
    next:   '#randomAkcioNext',
    prev:   '#randomAkcioPrev',
    easing:  'backinout'
  });

  $('#telephelyContainer').cycle({
    fx: 'fade',
    pause:  1,
    speed: 500,
    timeout: 3000
    //easing:  'backinout'
  });

  // container
  $('#tabMenu dl.tabs').kwicks({
        duration: 300,
        max: 270,
        spacing:  0
  });
  $('#tabMenu dl.tabs dt').click(function(){
    deleteCookie('open_box');
    $('#tabMenu  dl.tabs dd.tabContent').hide();
    $('#tabMenu  dl.tabs dd.tabContent').prev('dt').removeClass('open');
    $('#'+this.id+'_box').show();
    setCookie('open_box',this.id+'_box');
    $('#'+this.id+'_box').prev('dt').addClass('open');
  });

  var open_box = getCookie('open_box');
  if(open_box)
  {
    $('#tabMenu dl.tabs dd.tabContent').hide();
    $('#'+open_box).show();
    $('#'+open_box).prev('dt').addClass('open');
  }

    //gumikereső
    $('#gumiKereso form #kategoria').change(function(){
      if(this.value == $('#gumiKereso form #szezon_exclude').val())
      {
        $('#gumiKereso form div#gumikereso_szezon').fadeTo(0.5, 0.2);
        $('#gumiKereso form div#gumikereso_szezon input').attr('disabled', true);
      }
      else
      {
        $('#gumiKereso form div#gumikereso_szezon').fadeTo(0.5, 1);
        $('#gumiKereso form div#gumikereso_szezon input').attr('disabled', false);
      }
    })
  // termékek menü
	$('#termekek_lista').fademenu({
    slideup: 500, slidedown: 500, fadein: 100, fadeout: 50 });

  var submenusUpdated = new Array;
  
  $('#termekek_lista ul.submenu li.level2').mouseover(function(){
    var target_id = $(this).children('div.hover_menu').attr('id');
    if(!submenusUpdated[target_id])
    {
      $(this).children('div.hover_menu').html('<img alt="loading" src="/images/ajax-loader.gif" />');
    }
    $(this).children('div.hover_menu').show();
    
    if(!submenusUpdated[target_id])
      {
        jQuery.ajax({
            type:'POST',
            dataType:'html',
            success:function(data, textStatus){
                $('#'+target_id).html(data);
            },
            url:$(this).children('a').attr('href')
          });
        submenusUpdated[target_id] = true;
      }
  });

  $('#termekek_lista ul.submenu li.level2').mouseout(function(){
    $(this).children('div.hover_menu').hide();
  });

  // Akciós oldal
    $('#akciok div.akciosBox a strong').each(function (){
    var fontSize = 18;
    var minFontSize = 10;

    while($(this).parent().height()>38 && fontSize>minFontSize)
      {
        fontSize = fontSize - 2;
        $(this).css("font-size",fontSize+"px");
      }
    $(this).parent().css("height","38px");
  });


  $("a.lightbox").fancybox();
  
});

function sikeresKosarba()
{
  $("#tabMenu dl.tabs dt#kosarContainer").click();
  jAlert("<strong>A termék sikeresen bekerült a kosárba.</strong><br/> A <em>megrendelem</em> gombbal rögtön meg is rendelheti a kívánt termékeket vagy folyatathatja a vásárlást.", "Gumibomba.hu - Kosár"); 
  $("#tabMenu dl.tabs dt#kosarContainer").effect("highlight", null ,2000);
}

function getCookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ';', len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function setCookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	else
	{
		expires = 7 * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name+'='+ value +
		( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) + //expires.toGMTString()
		( ( path ) ? ';path=' + path : ';path=/' ) +
		( ( domain ) ? ';domain=' + domain : '' ) +
		( ( secure ) ? ';secure' : '' );
}

function deleteCookie( name, path, domain ) {
	if ( getCookie( name ) )
	{
	    document.cookie = name + '=' +
			( ( path ) ? ';path=' + path : '') +
			( ( domain ) ? ';domain=' + domain : '' ) +
			';expires=Thu, 01-Jan-1970 00:00:01 GMT';
	}
}
