/*
Function to hide and display objects ByID objectId = objest name that you wist to hide or display imageName
 */
function displayHide(objectId, imageNameOpen, imageNameClosed, appUrl) {
	if (document.getElementById) {

		var returnVar = document.getElementById(objectId);
		var returnImg = document.getElementById(objectId+'_img');

		if(returnVar.style.display=='block') {
			returnVar.style.display = 'none';
			if(returnImg) {
				returnImg.src = appUrl+'/images/'+imageNameClosed;
			}
		}
		else {
			returnVar.style.display = 'block';
			if(returnImg) {
				returnImg.src = appUrl+'/images/'+imageNameOpen;
			}
		}
	}
}

/*
Function hides the validator form the registration if company selected
*/
function hide_company_validators() {
	//document.getElementById('comp_hide1').style.display = 'none';
	//document.getElementById('comp_hide2').style.display = 'none';
	document.getElementById('comp_hide3').style.display = 'none';
	document.getElementById('comp_hide4').style.display = 'none';
	document.getElementById('comp_hide5').style.display = 'none';

}


/*
 * function that changes the images at the products page
 */
//function change_image(image, image_title, w, h, appurl) {
//
//	var imgsrc = '<a href="'+appurl+'/images_products/'+image+'_big.jpg" rel="facebox"><img src="'+appurl+'/images_products/'+image+'_a.jpg" alt="'+image_title+'" title="'+image_title+'" border="0" rel="facebox" width="'+w+'" height="'+h+'" style="display: block; margin-left: auto; margin-right: auto"/></a>';
//	document.getElementById("product_image").innerHTML = imgsrc;
//
//	jQuery(document).ready(function($) {
//		$('a[rel*=facebox]').facebox()
//	})
//}


/*
 * Banner function with mootools support
 * -----------------------------------------------
 */
var banners = 5;
var banner_width_closed = 40;
var wait_to_close = 0;
function get_new_div_width() {

	var div = document.getElementById("div_banner_top");
	var width = parseInt(div.clientWidth) - ((banners*banner_width_closed)+10);

	return width;
}

function get_open_banner_and_close_it() {
	for(i=1; i<=banners; i++) {
		var div_tmp = document.getElementById("ban"+i);
		var width_tmp = div_tmp.clientWidth + 30

		//run close on the current banner div
		if(width_tmp>banner_width_closed) {
			wait_to_close = 1;
			banner_action('ban'+i,'close');
		}
	}
}

function banner_action(div_id, action) {
	if(action=='open' && wait_to_close==0) {
		get_open_banner_and_close_it();
		var new_width = get_new_div_width();
		$(div_id).tween('width', new_width+'px');
	}
	else if(action=='close') {
		$(div_id).tween('width', banner_width_closed+'px');
		wait_to_close = 0;
	}
}

function fill_div(target, image, image_title, w, h, appurl, selected_option , main_option_id) {

	document.getElementById('product_image_a').href = appurl+image+'_big.jpg';
	document.getElementById(target).src = appurl+image+'_m.jpg';

	//$('#product_image_a').attr({href:appurl+image+'_big.jpg'});
	//$('#'+target).attr({src: appurl+image+'_a.jpg'});

	if(selected_option && selected_option > 0) {
		if(document.getElementById('product_option'+main_option_id)) {
			//opt_select = document.getElementById('product_option').value = selected_option;
			opt_select = document.getElementById('product_option'+main_option_id);
			for(ss = 0; ss <opt_select.length; ss++) {
				//alert(opt_select.options[ss].value);
				tmp_select_value = opt_select.options[ss].value;
				//alert(tmp_select_value.indexOf(selected_option+'::'));
				if(tmp_select_value.indexOf(selected_option+'::')==0) {
					opt_select.value = opt_select.options[ss].value;
				}
			}
		}
	}
}

/**
 * Product rate
 */
function rate_over(i, app_url) {
	//elem = document.getElementById("zvezdice");
 	//elem.src = APP_URL+"images/product_rate_"+(20*i)+".gif";

 	var target = '#zvezdice';
 	$(target).attr({src:app_url+'/images/product_rate_'+(20*i)+'.gif'});
 	//alert( $("#zvezdice").css("background") );
}
function rate_out(app_url) {
	var target = '#zvezdice';
 	$(target).attr({src:app_url+'/images/product_rate_0.gif'});
}


/* TOP MENU dropdown content */
/*
$(document).ready(function(){
  $("#top_navi-target-0").ezpz_tooltip({
  	contentPosition: 'belowStatic',
	stayOnContent: true,
	offset: -5
  });
  $("#top_navi-target-1").ezpz_tooltip({
  	contentPosition: 'belowStatic',
	stayOnContent: true,
	offset: -5
  });
  $("#top_navi-target-2").ezpz_tooltip({
  	contentPosition: 'belowStatic',
	stayOnContent: true,
	offset: -5
  });
  $("#top_navi-target-3").ezpz_tooltip({
  	contentPosition: 'belowStatic',
	stayOnContent: true,
	offset: -5
  });
  $("#top_navi-target-4").ezpz_tooltip({
  	contentPosition: 'belowStatic',
	stayOnContent: true,
	offset: -5
  });
  $("#top_navi-target-5").ezpz_tooltip({
  	contentPosition: 'belowStatic',
	stayOnContent: true,
	offset: -5
  });
  $("#top_navi-target-6").ezpz_tooltip({
  	contentPosition: 'belowStatic',
	stayOnContent: true,
	offset: -5
  });
  $("#top_navi-target-7").ezpz_tooltip({
  	contentPosition: 'belowStatic',
	stayOnContent: true,
	offset: -5
  });
});*/

function activate_zoom() {
	var options = {
	    zoomWidth: 250,
	    zoomHeight: 250
	};
	$('.image_zoom').jqzoom(options);
}

/*
$(document).ready(function(){
	activate_zoom();
});

$(document).ready(function(){
	$("#product_gift_target").ezpz_tooltip({
  	contentPosition: 'belowStatic',
	stayOnContent: true,
	offset: -5,
	contentId:"product_gift_content"
  	});
});
*/

function update_options_prices(option_main_id) {

	if($('#product_option'+option_main_id).val()) {

		op_value = $('#product_option'+option_main_id).val();
		//alert(op_value);
		tmp = op_value.split('::');

		if(tmp[1] && tmp[1].indexOf('~~')>0) {
			prices_tmp = tmp[1];
			prices = prices_tmp.split('~~');

			$("#po1").html(prices[0]);
			$("#po2").html(prices[1]);
			$("#po3").html(prices[2]);
		}

		if((tmp[1] && tmp[1].indexOf('§§')>0) || (tmp[2] && tmp[2].indexOf('§§')>0)) {

			load_tmp = (tmp[2])?tmp[2]:tmp[1];

			load = load_tmp.split('§§');
			// load new image
			if(load[0] && load[1] && load[2] && load[3] && load[4] && load[5] && load[6]) {
				fill_div( load[0], load[1], load[2], load[3], load[4], load[5], load[6]);

			}
		}
	}
}


window.addEvent('domready', function(){
	new FormCheck('email_news');
	new FormCheck('iskalnik');
	//new FormCheck('guestbook_form');
});