$(document).ready(function() { 
	$('#bm_opinie_button').bind('click', function() {
		$('#bm_opinie_button').slideUp('fast');
		$('#bm_opinie_form').slideDown('fast');
	});
});




function validate_basket()
{
    if (
            ( $('eraty_potwierdzenie') )
            &&
            ( $('eraty_potwierdzenie').checked == false )
            &&
            ( $('sprzedaz_ratalna').checked == true )
        )
    {
        alert ("Zanim złożysz zamówienie korzystajac z systemu ratalnego, zapoznaj sie z procedura udzielenia kredytu ratalnego eRaty Żagiel.");
        return false;
    }
    else if (
            ( $('platnosc_elektroniczna') )
            &&
            ( $('platnosc_elektroniczna').checked == true )
            &&
            ( document.getElementsByName("pay_type")[0].value == "" )
        )
    {
        alert ("Musisz wybrać rodzaj płatności elektronicznej!");
        return false;
    }
    else
    {
        return true;
    }
}

function preloader(base)
{
  var i = 0;
  imageObj = new Image();
  images = new Array();
  images[0]="artbox_up_b.jpg";
  images[1]="artbox_down_b.jpg";
  images[2]="promobox_left_b.jpg";
  images[3]="promobox_right_b.jpg";
  images[4]="page_nav_left_b.gif";
  images[5]="page_nav_right_b.gif";
  images[6]="bmbtn_a_a2.jpg";

  for(i=0; i<=3; i++) 
  {
    imageObj.src=base + images[i];
  }
}

function input_label(input, password)
{
  if (input.value == '')
  {
    if (password)
    {
      var newO = document.createElement('input');
      newO.setAttribute('type', 'text');
      newO.setAttribute('value', 'e-mail');
      newO.setAttribute('name', input.getAttribute('name'));
      newO.setAttribute('onfocus', 'input_label(this,true)');
      input.parentNode.replaceChild(newO, input);
    }
    else
    {
      input.value = input.defaultValue;
    }
  }
  else if (input.value == input.defaultValue)
  {
    if (password)
    {
      var newO = document.createElement('input');
      newO.setAttribute('type', 'password');
      newO.setAttribute('name', input.getAttribute('name'));
      newO.setAttribute('onblur', 'input_label(this,true)');
      input.parentNode.replaceChild(newO, input);
      newO.focus();
    }
    else
    {
      input.value = '';
    }
  }
}

function menu_bar_select(a)
{
  var temp = ['opony', 'felgi', 'bagazniki', 'lancuchy', 'serwis', 'inwest','akumulatory'];
  for (var i = 0; i < 7; i++)
  {
    if (temp[i] != a)
    {
      jQuery('#bar_a_btn_' + temp[i]).removeClass('active');
      jQuery('#bar_a_btn_a_' + temp[i]).hide();
      jQuery('#bar_a_btn_c_' + temp[i]).hide();
      jQuery('#bar_a_menu_' + temp[i]).hide();
    }
    else
    {
      jQuery('#bar_a_btn_' + a).addClass('active');
      jQuery('#bar_a_btn_a_' + a).show();
      jQuery('#bar_a_btn_c_' + a).show();
      jQuery('#bar_a_menu_' + a).show();
    }
  }
}

function bm_menu(type, a)
{
  var temp = null;
  if (type == 1)
  {
    temp = ['aktualnosci', 'eopon', 'efelg'];
  }
  else if (type == 2)
  {
    temp = ['opony', 'felgi', 'bagazniki', 'lancuchy', 'serwis', 'inwest'];
  }
  else if (type == 3)
  {
    temp = ['opis', 'opinie', 'gwarancja', 'raty', 'zapytaj', 'oznaczenia'];
  }
  for (var i = 0; i < temp.length; i++)
  {
    if (temp[i] != a)
    {
      jQuery('#bm_btn_b_' + temp[i]).removeClass('active');
      if (i == 0)
      {
        jQuery('#bm_btn_a_' + temp[i]).attr('src', img_path + 'bmbtn_a_a2.jpg');
      }
      else
      {
        jQuery('#bm_btn_a_' + temp[i]).attr('src', img_path + 'bmbtn_a_a.jpg');
      }
      jQuery('#bm_btn_c_' + temp[i]).attr('src', img_path + 'bmbtn_a_c.jpg');
      jQuery('#bm_' + temp[i]).hide();
    }
    else
    {
      jQuery('#bm_btn_b_' + a).addClass('active');
      jQuery('#bm_btn_a_' + a).attr('src', img_path + 'bmbtn_b_a.jpg');
      jQuery('#bm_btn_c_' + a).attr('src', img_path + 'bmbtn_b_c.jpg');
      jQuery('#bm_' + a).show();
    }
  }
}

function img_swap(img, file)
{
  img.src = file;
}

/* slider START */

var slider_id = 1;
var slider_count = 7;
var slider_timer = null;

function slider_sel(new_id)
{
  if (new_id != slider_id)
  {
    if (slider_timer)
    {
      clearTimeout(slider_timer);
    }
    jQuery('#slider_' + slider_id).fadeOut(750);
    jQuery('#slider_sel_' + slider_id).attr('class', 'clear');
    slider_id = new_id;
    jQuery('#slider_' + slider_id).fadeIn(750);
    jQuery('#slider_sel_' + slider_id).attr('class', 'selected');
    slider_timer = setTimeout('slider_down()', 5000);
  }
}

function slider_up()
{
  new_id = slider_id - 1;
  if (new_id == 0)
  {
    new_id = slider_count;
  }
  slider_sel(new_id);
}

function slider_down()
{
  new_id = slider_id + 1;
  if (new_id > slider_count)
  {
    new_id = 1;
  }
  slider_sel(new_id);
}

/* slider END */

function init_2()
{
  if (typeof document.addEventListener == 'function')
  {
    mppb_timer = setTimeout('mppb_right()', 3500);
    slider_timer = setTimeout('slider_down()', 5000);
  }
}

/* mainpage_product_box START */

var mppb_id = 0;
var mppb_timer = null;
var mppb_stp = false;
var mppb_count = 0;

function mppb_animate()
{
  if (mppb_timer)
  {
    clearTimeout(mppb_timer);
  }
  jQuery('#mppb_content').animate({marginLeft: "-" + (mppb_id * 180) + "px"}, 750);
  if (!mppb_stp)
  {
    mppb_timer = setTimeout('mppb_right()', 3500);
  }
}

function mppb_left()
{
  mppb_id++;
  if (mppb_id > mppb_count)
  {
    mppb_id = 1;
    jQuery('#mppb_content').animate({marginLeft: "0px"}, 0);
  }
  mppb_animate();
}

function mppb_right()
{
  mppb_id--;
  if (mppb_id < 0)
  {
    mppb_id = mppb_count - 1;
    jQuery('#mppb_content').animate({marginLeft: "-" + (mppb_count * 180) + "px"}, 0);
  }
  mppb_animate();
}

function mppb_stop()
{
  if (mppb_timer)
  {
    clearTimeout(mppb_timer);
  }
  mppb_stp = true;
}

function mppb_start()
{
  mppb_timer = setTimeout('mppb_left()', 3500);
  mppb_stp = false;
}

/* mainpage_product_box END */

function total_price(s, price)
{
  jQuery('#total_price').html(parseFloat(price * parseFloat(s.options[s.selectedIndex].value)).toFixed(2));
}

/* konfigurator START */ 

function rimChange( target, type )
{
    if ( !type )
        type = 'alloy';

    if ( type == 'scrub' )
    {
        if ( target == 'marka' )
        {
            removeOptions( 'seriascrub_id' );
            addOptions( 'markascrub', 'seria', type );
            submitDisabled();
        }
        else if ( target == 'seria' )
        {
            if ( jQuery('#seriascrub_id').val() > 0 )
                submitEnabled();    
            else
                submitDisabled();
        }
    }
    else if ( target == 'marka' )
    {
        removeOptions( 'seria_id' );
        removeOptions( 'model_id' );
        removeOptions( 'srednica_id' );
        addOptions( 'marka', 'seria', type );
        submitDisabled();
    }
    else if ( target == 'seria' )
    {
        removeOptions( 'model_id' );
        removeOptions( 'srednica_id' );
        addOptions( 'seria', 'model', type );
        submitDisabled();
    }
    else if ( target == 'model' )
    {
        removeOptions( 'srednica_id' );
        addOptions( 'model', 'srednica', type );
        submitDisabled();
    }
    else if ( target == 'srednica' )
    {
        if ( jQuery('#srednica_id').val() > 0 )
            submitEnabled();    
        else
            submitDisabled();
    }
}

function rimCheck()
{
    if ( ( jQuery('#srednica_id2').val() > 0 ) && ( jQuery('#producent_id2').val() != '' ) )
        submitEnabled( '2' );   
    else
        submitDisabled( '2' );
}

function removeOptions( target )
{
    /*for ( i = $( target ).length - 1; i >= 0; i-- )
    {
        $( target ).remove(i);
    }*/
    jQuery( '#' + target ).html('<option value="">-- wybierz --</option>');
    jQuery( '#' + target ).attr('disabled', 'disabled');
}

function addOptions( source, target, type )
{
    if (type == 'scrub')
    {
      target2 = target + 'scrub';
    }
    else
    {
      target2 = target;
    }
    id = jQuery('#'+source+'_id').val();

    if ( id > 0 )
    {
        // alert( '/ajax/rimparam/type/'+type+'/selected_param/'+target+'/id/' + id );
        jQuery( '#'+target2+'_id').load( '/ajax/rimparam/type/'+type+'/selected_param/'+target+'/id/' + id );
        jQuery( '#'+target2+'_id' ).removeAttr('disabled');
    }
}

function submitDisabled( suffix )
{
    if ( !suffix )
        suffix = '';
    jQuery( '#szukaj_felgi'+suffix ).attr('disabled', 'disabled');
    jQuery( '#szukaj_felgi'+suffix ).attr( 'class', 'szukaj_disabled' );
}

function submitEnabled( suffix )
{
    if ( !suffix )
        suffix = '';
    jQuery( '#szukaj_felgi'+suffix ).removeAttr('disabled');
    jQuery( '#szukaj_felgi'+suffix ).attr( 'class', 'szukaj_enabled' );
}

/* konfigruator END */

/* promocje w zakladkach START */

var promo_curr = new Array();
promo_curr['opony'] = 1;
promo_curr['felgi'] = 1;
promo_curr['bagazniki'] = 1;
promo_curr['lancuchy'] = 1;
promo_curr['serwis'] = 1;
promo_curr['inwest'] = 1;

function promo_page(id, page)
{
  jQuery('.promo_link_' + id).removeClass('active');
  jQuery('#promo_' + id + '_' + page).addClass('active');
  jQuery('.bm_' + id).hide();
  jQuery('#bm_' + id + '_' + page).show();
  promo_curr[id] = page;
}

function promo_page_left(id)
{
  if (promo_curr[id] > 1)
  {
    promo_page(id, promo_curr[id] - 1);
  }
}

function promo_page_right(id)
{
  if (jQuery('#bm_' + id + '_' + (promo_curr[id] + 1)).length)
  {
    promo_page(id, promo_curr[id] + 1);
  }
}

/* promocje w zakladkach END */

/* SEO */

function SeoButton(opt)
{
	var m_this = this, m_button_show, m_button_hide, m_content, m_bottom, m_visible, m_bussy, 
		m_height, m_speed = 1000;
	
	function _construct(opt)
	{
		m_bussy = false;
		m_visible = false;
		m_button_show = jQuery(opt.btnShow);
		m_button_hide = jQuery(opt.btnHide);
		m_content = jQuery(opt.content);
		m_bottom = jQuery(opt.bottom);
		m_height = m_content.css("height");
		
		m_button_show.click(m_this.toggleContent);
		m_button_hide.click(m_this.toggleContent);
	}
	
	this.toggleContent = function()
	{
		if (!m_bussy)
		{
			m_bussy = true;
			
			if (m_visible)
			{
				m_visible = false;
				m_content.animate({ height: m_height }, m_speed, function() {
					m_bussy = false;
					m_button_hide.hide();
					m_button_show.show();
				});
				m_bottom.animate({ marginTop: "20px" }, m_speed);
			}
			else
			{
				m_visible = true;
				m_content.animate({ height: "180px" }, m_speed, function() {
					m_bussy = false;
				});
				m_bottom.animate({ marginTop: "180px" }, m_speed);
				m_button_hide.show();
				m_button_show.hide();
			}
		}
	}
	
	_construct(opt);
}


$(document).ready(function() { 
	$('#stars img').bind('mouseover', function() {
		selected_star = $(this).attr('id').charAt(5);

		for ( i = 1; i <= 5; i++ )
		{
			if ( i <= selected_star )
				trigger = 'middle';
			else
				trigger = 'off';
			$("#star_"+i).attr( "src", "/public/images/oponix2/star_"+trigger+".png" );
		}
	});
	
	$('#stars img').bind('mouseout', function() {
		selected_star = $("#dane_kontaktowe_opinie-score").val();

		for ( i = 1; i <= 5; i++ )
		{
			if ( i <= selected_star )
				trigger = 'on';
			else
				trigger = 'off';
			$("#star_"+i).attr( "src", "/public/images/oponix2/star_"+trigger+".png" );
		}
	});

	$('#stars img').bind('click', function() {
		selected_star = $(this).attr('id').charAt(5);

		$("#dane_kontaktowe_opinie-score").val( selected_star );

		for ( i = 1; i <= 5; i++ )
		{
			if ( i <= selected_star )
				trigger = 'on';
			else
				trigger = 'off';
			$("#star_"+i).attr( "src", "/public/images/oponix2/star_"+trigger+".png" );
		}
		
	});
});



/* SEO END */
