// JavaScript Document

var products = "";

document.observe("dom:loaded", function() {

    products = $$(".products_hidden");
    if(products.length > 1) {
        $("mainNews_rightarrow").observe("click", change_products.bindAsEventListener(this,"right"));
        $("mainNews_leftarrow").observe("click", change_products.bindAsEventListener(this,"left"));
    }

    $$("#international a").each(function(el) {
        el.observe("click", function() {
              if($("div_overlay") === null || $("div_overlay") == "undefined") {
                  div = new Element("div", { id: "div_overlay"});
                  div.style.position = "absolute";
                  div.style.left = "0px";
                  div.style.top = "0px";
                  div.style.zindex = "200";
                  div.style.width = "100%";
                  div.style.height = ($("body").offsetHeight + 60) + "px";
                  div.style.display = "block";
                  div.style.backgroundColor = "black";
                  div.style.opacity = "0.5";
                  $("body").appendChild(div);
              } else {
                  $("div_overlay").style.display = "block";
              }

              $("sitescontainer").style.display = "block";

              $$(".jqmClose,#div_overlay").each(function(el) {
                  el.observe("click", function(ev) {
                      ev.stop();
                      $("div_overlay").style.display = "none";
                      $("sitescontainer").style.display = "none";
                  });
              });
        });
    });

    $$(".sub").each(function(el) {

          el.observe("mouseover", function() {

                submenu = el.down().next();
                submenu.style.display = "block";

          });

          el.observe("mouseout", function() {

                submenu = el.down().next();
                submenu.style.display = "none";

          });

    });

});


left_product_index = 0;

function change_products(ev, dir) {
  ev.stop();

	if(dir == "left") {
		container1 = $("mainNews_rightbox");
		container2 = $("mainNews_leftbox");
		if(left_product_index==products.length-1){
			left_product_index = 0;
		} else {
			++left_product_index;
		}
		var new_product_index = (left_product_index +1) % products.length;
	} else {
		container1 = $("mainNews_leftbox");
		container2 = $("mainNews_rightbox");
		if(left_product_index==0){
			left_product_index = products.length-1;
		} else {
			--left_product_index;
		}
		var new_product_index = left_product_index;
	}


	var li = products[new_product_index];
	var c_header = li.down().innerHTML;
	var c_price = li.down().next().innerHTML;
	var c_session = li.down().next().next().innerHTML;
	var c_description = li.down().next().next().next().innerHTML;
	var c_image = li.down().next().next().next().next().innerHTML;
	var c_url = li.down().next().next().next().next().next().innerHTML;

	container2.innerHTML = container1.innerHTML;

	container1.down("h3").innerHTML = c_header == '' ? '&nbsp;' : c_header;
	container1.down(".price strong").innerHTML = c_price == '' ? '&nbsp;' : c_price;
	container1.down("span.session").innerHTML = c_session == '' ? '&nbsp;' : c_session;
	container1.down(".description").innerHTML = c_description == '' ? '&nbsp;' : c_description;
	var img_src = container1.down(".product_image img").src;
	img_segs = img_src.split("/");
	img_segs[img_segs.length-1] = c_image;
	img_src = img_segs.join("/");
	container1.down(".product_image img").src = img_src;

	container1.down(".redButton").href = c_url == '' ? '&nbsp;' : c_url;
	container1.down(".header_link").href = c_url == '' ? '&nbsp;' : c_url;
}

