
MAG.onSelectValueChange = function(options){
	if(options === undefined){
		var options = {};
	}

	if(this.value == 0){
		self.location = self.location.pathname;
	}else{
		self.location = (options.url ? options.url : '') + (options.key ? options.key : '') + this.value;
	}
};

$(document).ready(function(){
	teaserSlider($('#why_cadooz p'), $('#why_cadooz_next'), $('#why_cadooz_prev'), 9, 285);
	teaserSlider($('#facts_quotes p'), $('#facts_quotes .arrow_right'), $('#facts_quotes .arrow_left'), 6, 276);
	teaserSlider($('#glosary'), $('#glosary_next'), $('#glosary_prev'), 5, 265);

	function teaserSlider(box, next, prev, max_index, width){
		if(box && box.length){
			var index = 0;

			next.click(function(){
				getTeaser(index + 1);
			});

			prev.click(function(){
				getTeaser(index - 1);
			});

			function getTeaser(get_index){
				if(get_index < 0 || get_index > max_index){
					return;
				}

				if(get_index == max_index){
					next.addClass('disabled');
				}else if(get_index == 0){
					prev.addClass('disabled');
				}else{
					next.removeClass('disabled');
					prev.removeClass('disabled');
				}


				index = get_index;

				box.css('backgroundPosition', (width * -get_index) + 'px 0');
			}
		}
	}

	$('a.iframe').click(function() {
		$('#content_for_layout').html('<iframe style="width: 100%; height: 510px; overflow: hidden;" frameborder="0" name="search_frame" onload="window.top.set_iframe_size();" src="' + this.href + '"></iframe>');
		return false;
	});
});

var set_iframe_size = (function() {
	var cnt = 0;

	return function() {
		var iframe = $('#content_for_layout iframe');
		iframe.height(cnt++ ? 710 : 510);	// hardcoded - the only way to avoid xss
	};
})();

function showHideFaq(sender, tag_name) {
	var faq_cnt = sender.parentNode.getElementsByTagName(tag_name || 'ul')[0],
		dspl;

	if (faq_cnt) {
		dspl = faq_cnt.style.display ? '' : 'block';
		faq_cnt.style.display = dspl;
		if (dspl) {
			sender.className += ' active_faq';
		} else {
			sender.className = sender.className.slice(0, -11);
		}
	}
}
