/* положения стрелки на баннере products */
var arrow = new Array ("81px","285px","506px");
(new Image()).src = '/i/submenu_bg.png';
(new Image()).src = '/i/megamenu_bg.png';

$(document).ready(function() {

	$(".t, .b, .t_box_corners, .b_box_corners, div#support a").pngfix();

	/* Products */
	window.products = $("#products").scrollable({
		size: 1,
		clickable: false,
		keyboard: false,
		loop: true,
		onBeforeSeek: function(e,n) {
			$("#prod_arrow").animate({ left: arrow[n] }, 300, 'linear');
		}
	}).navigator({
		navi: "#products_nav",
		naviItem: 'a'
	}).autoscroll({
		interval: 8000,
		autostart: true,
		autopause: true,
		api: true
	});

	$("#products_nav a").click( function(event) {
		event.preventDefault();
		products.stop();
	});
	/* Video */
	$(".video_total").text($("#video .items div").length);

	$("#video").scrollable({
		size: 1,
		clickable: false,
		keyboard: false,
		loop: false,
		next: "#video li.next a",
		prev: "#video li.prev a",
		onBeforeSeek: function(e,n) {
			$(".video_page").text(n+1);
			try { $("#video embed").get(this.getIndex()).pauseVideo(); } catch (e) {};
		}
	});

	/* ABC */
	$("#abc_total").text($("#abc .items > div").length);

	$("#abc").scrollable({
		size: 1,
		clickable: false,
		keyboard: false,
		loop: false,
		next: "#abc li.next a",
		prev: "#abc li.prev a",
		onBeforeSeek: function(e,n) {
			$("#abc_page").text(n+1);
		}
	});

	/* Buttons */
	$("li.next a, li.prev a").click( function(event) {
		event.preventDefault();
	}).mousedown(function(){
		$("li.next a, li.prev a").removeClass("click");
		$(this).addClass("click");
	}).mouseup(function(){
		$(this).removeClass("click");
	});

	/* Menu */
	var config = {
		sensitivity: 1,
		interval: 0,
		over: makeTall,
		timeout: 300,
		out: makeShort
	};

	$("#menu ul li").hoverIntent(config);
	/* Удалить это после debug */
	/*.hover(function() {
		$(this).addClass("subhover"); //On hover over, add class “subhover”
	}, function(){ //On Hover Out
		$(this).removeClass("subhover"); //On hover out, remove class “subhover”
	})*/

	$(".aslide").slideshow({
		width:200,      // width in px
		height:180,     // height in px
		time:2000,      // time out beetwen slides
		titleshow:false,// always show title
		title:false,
		panel:false,     // show controls panel
		play:true,     // play slideshow
		effect:'fade',  // aviable fade, scrollUp/Down/Left/Right, zoom, zoomFade, growX, growY
		effecttime:500,// aviable fast,slow,normal and any valid fx speed value
		filter:true,    // remove <br/>, empty <div>, <p> and other stuff
		playhoverr:false,     // bind content hover stop/play (reverse of playhover)
		playframe:false,       // show frame "Play Now!"
		loadframe:true       // show frame with "loading"
	});

	/* Image Fancybox */
	var fancy_params = {
		"autoScale" : false,
		"overlayShow" : false,
		"titlePosition" : "inside",
		"transitionIn" : "elastic",
		"transitionOut" : "elastic",
		"speedIn" : 500,
		"speedOut" : 300,
		"showNavArrows" : true,
		"margin" : 30,
		"autoDimensions": true,
		"type" : "image"
	};

	$("a.fancy_diplom").attr('rel', 'gallery').fancybox(fancy_params);

	fancy_params.autoScale = "true";
	$("a.fancybox:has(img), a.fancybox[href$=.jpg], a.fancybox[href$=.png], a.fancybox[href$=.gif], a.fancy_img").attr('rel', 'gallery').fancybox(fancy_params);
	$("a.fancy_gallery").fancybox(fancy_params);

	/* swf */
	fancy_params.type = "swf";
	$("a.fancybox[href$='.swf']").fancybox(fancy_params);

	/* ttx */
	fancy_params.type = "";
	$("table.ttx tr:odd").css("background-color", "#ccccfe");
	$("a.fancybox[href*='#']").fancybox(fancy_params);

	/* Price Logic */
	$(".PriceList td.Item div.description.more").css('display', 'none');

	$(".PriceList td.Item.flip").toggle(
		function(event) {
			event.preventDefault();
			$(this).find("a.more").text(' ▲ ');
			$(this).find("span.Item-name").css('font-weight', 'bold');
			$(this).find("div.description").slideDown(70);
		},
		function(event) {
			event.preventDefault();
			$(this).find("a.more").text(' ► ');
			$(this).find("span.Item-name").css('font-weight', 'normal');
			$(this).find("div.description").slideUp(70);

		});

	$("[placeholder]").each(function(){
			inputPlaceholder(this);
	})

});

function makeTall(){
	$(this).find("ul.subnav, ul.meganav").slideDown(70);
}
function makeShort(){
	$(this).find("ul.subnav, ul.meganav").slideUp(70);
}

/**
 * Example: inputPlaceholder( document.getElementById('my_input_element') )
 * @param {Element} input
 * @param {String} [color='#AAA']
 * @return {Element} input
 */
function inputPlaceholder (input, color) {

	if (!input) return null;

	// Do nothing if placeholder supported by the browser (Webkit, Firefox 3.7)
	if (input.placeholder && 'placeholder' in document.createElement(input.tagName)) return input;

	color = color || '#AAA';
	var default_color = input.style.color;
	var placeholder = input.getAttribute('placeholder');

	if (input.value === '' || input.value == placeholder) {
		input.value = placeholder;
		input.style.color = color;
		input.setAttribute('data-placeholder-visible', 'true');
	}

	var add_event = /*@cc_on'attachEvent'||@*/'addEventListener';

	input[add_event](/*@cc_on'on'+@*/'focus', function(){
	 input.style.color = default_color;
	 if (input.getAttribute('data-placeholder-visible')) {
		 input.setAttribute('data-placeholder-visible', '');
		 input.value = '';
	 }
	}, false);

	input[add_event](/*@cc_on'on'+@*/'blur', function(){
		if (input.value === '') {
			input.setAttribute('data-placeholder-visible', 'true');
			input.value = placeholder;
			input.style.color = color;
		} else {
			input.style.color = default_color;
			input.setAttribute('data-placeholder-visible', '');
		}
	}, false);

	input.form && input.form[add_event](/*@cc_on'on'+@*/'submit', function(){
		if (input.getAttribute('data-placeholder-visible')) {
			input.value = '';
		}
	}, false);

	return input;
}

/* Pop-up */
function popupWin(uri, wdt, hgt) {
	if ( screen.height - 50 < hgt ) {hgt = screen.height - 50;}
	if ( screen.width < wdt ) {wdt = screen.width;}
	posX = Math.round((screen.width - wdt) / 2);
	posY = Math.round((screen.height - hgt) / 2);
	popupedWin = window.open(uri, "popup", "status=yes,menubar=no,toolbar=no,resizable=no,scrollbars=yes,location=no,width="+wdt+",height="+hgt+",left="+posX+",top="+posY);
	popupedWin.focus();
}

function support() {
	popupWin('/about/support.html', 410, 760);
}
