// JavaScript Document
function startList(){
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("container_menu1");
		if(navRoot){
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if(node.nodeName=="DIV") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
				break;
			}
		}}
		navRoot = document.getElementById("main");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if(node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
}

jQuery(document).ready(function(){
	jQuery('.atooltip').tooltip({
		delay: 0,
		showURL: false
	});
	jQuery('.product_brief_block').hover(
	  function () {
	    jQuery(this).find('.prdbrief_name').css("background","#eee");
	    jQuery(this).find('.prdbrief_thumbnail').css("border","2px solid #009807");
	  }, 
	  function () {
	    jQuery(this).find('.prdbrief_name').css("background","none");
	    jQuery(this).find('.prdbrief_thumbnail').css("border","2px solid #fff");
	  }
	);
	jQuery('.cpt_product_related_products img,.recommend img,.cart_recommend img').hover(
	  function () {
	    jQuery(this).css("border","2px solid #009807");
	  }, 
	  function () {
	    jQuery(this).css("border","2px solid #fff");
	  }
	);
	jQuery('#sio .cpt_auxpages_navigation a:first').css({'color':'red','font-weight':'bold'});

	jQuery(".recommend a,.cart_recommend a").click(function(event){
		event.preventDefault();
		my_window = window.open('/popup.html', "window_r","status=0,width=820,height=450,location=no,directories=0,menubar=no,toolbar=no,scrollbars=yes,resizable=yes"); 
		link = jQuery(this).attr("href");

		jQuery.get(link, function(data) {
		  var mydoc = my_window.document;
		  mydoc.write(data);
		  setTimeout(init_mydoc, 500, mydoc, link);
		});
	});
	function init_mydoc(mydoc,link) {
		jQuery(mydoc).find('#all').html(jQuery(mydoc).find(".cpt_maincontent").parent().html());

		jQuery(mydoc).find('.current-rating1').css("margin-top","-8px");
		jQuery(mydoc).find('select[name=zoneIDx]').attr("disabled","disabled");
		jQuery(mydoc).find('.cpt_product_related_products').remove();
		jQuery(mydoc).find('.stext').remove();
		jQuery(mydoc).find('.unit-vote').next().remove();
		jQuery(mydoc).find('.unit-vote').remove();
		jQuery(mydoc).find('.cpt_product_category_info').remove();
		jQuery(mydoc).find('#box_product_thumbnails').remove();
		jQuery(mydoc).find('#print').remove();
		jQuery(mydoc).find('#buylink').remove();

		jQuery(mydoc).find('.product_option').change(function(){
		  var parameter = jQuery(mydoc).find('.product_option').val();
		    jQuery(mydoc).find('#price .totalPrice').html(jQuery(mydoc).find('.product_option option[value='+parameter+']').attr("rel")+' <em>грн</em>');

		    if(jQuery(mydoc).find('#price_d').size()){
		      var discount = jQuery(mydoc).find('#disco_'+parameter);
		      if(discount.length) discount = jQuery(discount).html();
		      else discount = 0;
		      if(discount){
			jQuery(mydoc).find('#pcrossb').show();
			jQuery(mydoc).find('#price_d').show().find(".discoPrice").html(discount+' <em>грн</em>');
		      }
		    }
		});
		
		jQuery(mydoc).find('.product_option').change();

		jQuery(mydoc).find('.prdd_top:eq(0) a').click(function(event){
						event.preventDefault();
						my_window.close();
						window.location=link;
					  });
		jQuery(mydoc).find('.prdd_top:eq(1) a').click(function(event){
						event.preventDefault();
						my_window.close();
						window.location=jQuery(this).attr("href");
					  });
		jQuery(mydoc).find('#add2cart').click(function(){
						var formdata=jQuery(mydoc).find('form[name=prd_info_form]').serialize();
						my_window.close();
						jQuery.post(jQuery(mydoc).find('form[name=prd_info_form]').attr("action"),
						formdata+'&add2cart.x=1&add2cart.y=1',
						function(data) {
							window.location.reload();
						});
						return false;
					  });
		jQuery(mydoc).find('#tabs li:eq(1)').hide();
		jQuery(mydoc).find('#tabs li:eq(2)').hide();
		jQuery(mydoc).find('#tabs').tabs();
	}
	
    jQuery("#tabs").tabs();
});
