$(document).ready(function() {
  $.tabs('container-1', 1);
});

/*
//old image browser
$(document).ready(function() {
  var imglinks = '';
  $("#pd-imgs img").each(function(index) {
    imglinks += '<a href="#">'+(index+1)+'</a>';
  });
  if (imglinks != '') {
    $("#pd-imgs").after('<div id="pd-imgbrowser">'+imglinks+'</div>');
  }

  $("#pd-imgs img").hide();
  $("#pd-imgs img:first").show();
  $("#pd-imgbrowser a:first").addClass("active");
  $("#pd-imgbrowser a").each(function(index) {
    $(this).click(function() {
      $("#pd-imgbrowser a").removeClass("active");
      $(this).addClass("active");
      $("#pd-imgs img").hide();
      $("#pd-imgs img:eq("+index+")").show();
      return false;
    });

  });
});
*/

$(document).ready(function() {
  $("#pd-imgs").after('<div id="pd-imgbrowser"></div>').find("img").clone().appendTo("#pd-imgbrowser");
  $("#pd-imgbrowser img").each(function(index) {
    $(this).attr("width", $(this).attr("width")/4);
    $(this).attr("height", $(this).attr("height")/4);
  });

  $("#pd-imgs img").hide();
  $("#pd-imgs img:first").show();

  $("#pd-imgbrowser img:first").addClass("active");
  $("#pd-imgbrowser img").hover(function(){
    $(this).addClass("imghover");
  },function(){
    $(this).removeClass("imghover");
  });

  $("#pd-imgbrowser img").each(function(index) {
    $(this).click(function() {
      $("#pd-imgbrowser img").removeClass("active");
      $(this).addClass("active");
      $("#pd-imgs img").hide();
      $("#pd-imgs img:eq("+index+")").show();
      //return false;
    });

  });
});


$(document).ready(function() {
  var $cProdName = readCookie('productName');
  var $cProdModel = readCookie('productModel');

  $("#mailformproduct_name").val($cProdName);
  $("#mailformitem_no").val($cProdModel);

  //eraseCookie('productName');
  //eraseCookie('productModel');

  $(".btn-inquire a").click(function(){
    eraseCookie('productName');
    eraseCookie('productModel');
    createCookie('productName', $("#inq-pname").val(), 365);
    createCookie('productModel', $("#inq-pmodel").val(), 365);
  });

  $(".pl-link-inquire a").click(function(){
    eraseCookie('productName');
    eraseCookie('productModel');
    createCookie('productName', $(this).parents(".pl-item").find(".pl-inq-pname").val(), 365);
    createCookie('productModel', $(this).parents(".pl-item").find(".pl-inq-pmodel").val(), 365);
  });

});

// cookie functions http://www.quirksmode.org/js/cookies.html
function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name)
{
	createCookie(name,"",-1);
}
// /cookie functions
