if (typeof playlist_params != 'undefined') {
	swfobject.embedSWF(
		'/player/player.swf', 'playerflash', '567', '384', '8.0.0', '/images/expressInstall.swf',
		{ _xmlpath: '/player/playlistXML.jsp' + playlist_params,  _xmlpathplayer: '/player/playlistXML.jsp' + playlist_params },
		{ wmode: 'transparent', menu: 'false' }
	)
}
if (typeof mobile_params != 'undefined') {
	swfobject.embedSWF(
		'/player/playeringame.swf', 'playerflash', '211', '374', '8.0.0', '/images/expressInstall.swf',
		{ path: mobile_params, sound: mobile_sound },
		{ wmode: 'transparent', menu: 'false' }
	)
}

if (typeof film_params != 'undefined') {
	swfobject.embedSWF(
		'/player/player.swf', 'playerflash', '567', '384', '8.0.0', '/images/expressInstall.swf',
		{ _xmlpath: '/player/playlistXML.jsp' + film_params,  _xmlpathplayer: '/player/playlistXML.jsp' + film_params },
		{ wmode: 'transparent', menu: 'false' }
	)
}

document.onclick = function(e) {
	var imagePopup = function(url, width, height) {
		var w = window.open(url, '_blank', 'width=' + width + ',height=' + height + ',resizable=yes')
		w.document.open()

		w.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'+"\n");
		w.document.write('<html><head>');
		w.document.write('<style>html, body { padding: 0; margin: 0; background: #FFFFFF;  height: 100%;}')
		w.document.write(' img {margin:0; border: none;} </style>')
		w.document.write('</head><body>');
		w.document.write('<img src="' + url + '" width="' + width + '" height="' + height + '" border="0" alt=""></body></html>')

		w.document.close();
		w.focus();

		return false;
	}

	var textPopup = function(url, name, width, height, scrollbars) {
		window.open(url, name, 'width=' + width + ',height=' + height + ',resizable=yes' + (scrollbars ? ',scrollbars=yes' : ''))
		return false;
	}

	e = e || event

	if (e.button != 0) {
		return true
	}

	var t = e.target || e.srcElement
	while (t && t.nodeType == 1 && t.tagName.toLowerCase() != 'a') {
		t = t.parentNode
	}

	if (!t || t.nodeType != 1) {
		return true
	}

	if (/\bglowing\b/.test(t.className)) {
		size = t.getAttribute('popup').split(' ')

		return imagePopup(t.href, (parseInt(size[0]) || '320'), (parseInt(size[1]) || '240'));
	}

	if (/\bdownload\b/.test(t.className)) {
		size = t.getAttribute('popup').split('x')

		return textPopup(t.href, '_blank', (parseInt(size[0]) || '800'), (parseInt(size[1]) || '600'), true);
	}

	if (/\bpreviews\b/.test(t.parentNode.className) && /\bmobile\b/.test(t.parentNode.parentNode.className)) {
		size = t.hash.substr(1).split(',')


		return imagePopup(t.href, (parseInt(size[0]) || '320'), (parseInt(size[1]) || '240'));
	}
	if (/\bpreviews\b/.test(t.parentNode.className) && /\bmovies\b/.test(t.parentNode.parentNode.className)) {
		size = t.getAttribute('popup').split(' ')

		return imagePopup(t.href, (parseInt(size[0]) || '800'), (parseInt(size[1]) || '422'));
	}
	if (/\bpreviews\b/.test(t.parentNode.className) && /\pc\b/.test(t.parentNode.parentNode.className)) {
		size = t.getAttribute('popup').split(' ')

		return imagePopup(t.href, (parseInt(size[0]) || '800'), (parseInt(size[1]) || '600'));
	}
	if (/\bpreviews\b/.test(t.parentNode.className) && /\mobile\b/.test(t.parentNode.parentNode.className)) {
		size = t.getAttribute('popup').split(' ')

		return imagePopup(t.href, (parseInt(size[0]) || '240'), (parseInt(size[1]) || '320'));
	}

	if (/\bpreviews\b/.test(t.parentNode.className)) {
		return textPopup('/player/screenshot.jsp?' + t.href, 'previews', 820, 620, false)
	}

	if (/\bprint\b/.test(t.target)) {
		return textPopup(t.href, '_blank', 820, 620, true)
	}

	if (/\btrailers\b/.test(t.parentNode.className)) {
		return textPopup(t.href, 'trailers', 588, 397, false)
	}

	if(/\bbanner\b/.test(t.target)) {
		size = t.name.split(',')
		return textPopup(t.href, '_blank', (parseInt(size[0]) || '600'), (parseInt(size[1]) || '480'), false)
	}

	if (/\bdvdcover\b/.test(t.target)) {
		size = t.hash.substr(1).split(',')
		return imagePopup(t.href, (parseInt(size[0]) || '425'), (parseInt(size[1]) || '600'));
	}

	if (/\bgamecover\b/.test(t.target)) {
		size = t.getAttribute('popup').split(' ')

		return imagePopup(t.href, (parseInt(size[0]) || '320'), (parseInt(size[1]) || '240'));
	}

	if(/\bveil\b/.test(t.className)) {
		document.body.className += ' veil';

		var veilIframe = document.getElementById('popupframe');

		var hash = (t.href.indexOf('#') > -1) ? t.href.substr(t.href.indexOf('#') + 1) : '';

		if(hash.length > 0 && (hashNode = document.getElementById(hash))) {
			veilIframe.innerHTML = '<div>' + hashNode.innerHTML + '</div>';

		} else {
			veilIframe.innerHTML = '<iframe frameborder="0" src="' + t.href + '"></iframe';
		}

		window.scrollTo(0,0);

		return false;
	}

	if(t.id == 'closeVeil') {
		document.body.className = document.body.className.replace(/ veil/g, '');
		return false;
	}

	return true
}


$(function() {
	$(".phone .allmodels span").click(function() {
		$(".phone .full").not($(this).parents("dd")).removeClass("full");
		$(this).parents("dd").toggleClass("full");
	});
});
$(function() {
	$("body.archive #content ul.othernews").slice(1).hide();
	$("body.archive #content h3").slice(0,1).addClass("openlist");
	$("body.archive #content h3").click(function() {
		$(this).next("ul").toggle();
		$(this).toggleClass("openlist");
		$(this).parents().children("h3").not($(this)).removeClass("openlist");
		$(this).nextAll("ul").not($(this).next("ul")).hide();
		$(this).prevAll("ul").hide();
	});
});

$(document).ready(function() {
	var dvdPromoItem = document.getElementById("dvd-promo-item");

	if (dvdPromoItem) {
		var externalScript = document.createElement("script");

		var onLoadScript = function () {
			var buttons = "";

			$.each(dvdSoon, function(i) {
				if (dvdSoon[i] != 0) {
					if (dvdSoon[i].current) {
						$('#slideshow-img').load(function() {
							$(this).show();
						}).attr("src", dvdSoon[i].image);
	
						$("#slideshow-link").attr({
							"href": dvdSoon[i].clk,
							"dimensions": dvdSoon[i].popup
						});
	
						if (!window.location.hash) {
							carouselSlideshow.selectThumb(dvdSoon[i].url);
						}
	
						if (dvdSoon[i].soon == 1) {
							$(".dvd-promo-soon").show();
						} else {
							$(".dvd-promo-soon").hide();
						}
	
						buttonsAttrs = ' id="slideshow-current" class="slideshow-current" ';
	
					} else {
						buttonsAttrs = '';
					}
	
					buttons += '<a href="' + dvdSoon[i].url + '" image="'+dvdSoon[i].image+'" title="'+ dvdSoon[i].title + '" rel="'+dvdSoon[i].url + '" rev="' + dvdSoon[i].soon + '" dimensions="'+ dvdSoon[i].popup + '" ' + buttonsAttrs + '>';
					buttons += '<img src="' + dvdSoon[i].button + '" alt="' + dvdSoon[i].title + '"/>';
					buttons += '</a>';
				}
			});
	
			$("#slideshow-buttons").html(buttons);
			initButtons();

			with (carouselSlideshow) {
				init();
				startPromoCycle(promoTimeout);
			}
		};

		externalScript.type="text/javascript";
		externalScript.onreadystatechange = function () {
			if (this.readyState == 'loaded' || this.readyState == 'complete') {
				onLoadScript.apply(this);
			}
		}

		externalScript.onload = onLoadScript;
		externalScript.src = dvdPromoItem.getAttribute('path');
	
		var nodeBefore = document.getElementById("slideshow-link");
		dvdPromoItem.insertBefore(externalScript, nodeBefore);
	}
});

function initButtons(){
	var img = $('#slideshow-img');

	if (img) {
		var link = $('#slideshow-link');
		var currentClass = 'slideshow-current';

		$('#slideshow-buttons a').click(function() {
			if (!$(this).hasClass(currentClass)) {
				$('.' + currentClass).removeClass(currentClass);
				$(this).addClass(currentClass);

				img.attr('src', $(this).attr('image')); // previews are now loaded to #image-preloadings in changeflash.js

				link.attr({
					'href': $(this).attr('rel'),
					'dimensions': $(this).attr('dimensions')
				});

				if ($(this).attr('rev') != '') {
					$('.dvd-promo-soon').show();
				} else {
					$('.dvd-promo-soon').hide();
				}

				with (carouselSlideshow) {
					//selectThumb(this.rel);
					
					if (!promoTriggered) {
						restartPromoCycle();
					}
				}
			}

			return false;
		});
	}
}


$(function() {
	$("body.video #content #playlists h4").click(function() {
		$(this).next("ul").andSelf().toggleClass("opened");
	})

	$("body.video #content #playlists h4 a").click(function(e) {
		$(this).parent("h4").trigger("click");
		return false;
	})
});

$(function() {
	$('#main #video-menu form input.text'
	).each(function() {
		this.defVal = this.value;
	}).focus(function() {
		if (this.value == this.defVal) {
			this.value = '';
		}
	}).blur(function() {
		if (this.value == '') {
			this.value = this.defVal;
		}
	});
});

$(function() {
	$('#search-keyword'
	).each(function() {
		this.defVal = this.value;
	}).focus(function() {
		if (this.value == this.defVal) this.value = '';
		$(this).parents().eq(0).addClass('search-keyword-active');
	}).blur(function() {
		if (this.value == '') this.value = this.defVal;
		$(this).parents().eq(0).removeClass('search-keyword-active');
	});
});

function onSearchComplete(sc, searcher) {
	if(window.cto) {
		cto.ajaxStart();
		cto.pageName = 'search';
		cto.internalSearchPhrase = sc.input.value;
		cto.eventType = 'internalSearch';
		cto.ajaxSubmit();
	}

	if (searcher.results && searcher.results.length > 0) {
		$('.jsbanner').hide();
		var gs = $('#searchcontrol');

		$('#searchcontrol').hide().queue(function() {
			$('#gs-noresults').hide();

			$('div.gs-visibleUrl-long', gs).each(function() {
				$(this).wrapInner('<a href="http://' + $(this).text() + '"></a>');
			});

			$('div.gs-result', gs).each(function(i) {
				$(this).prepend('<div class="gs-counter">' + (i + 1 + searcher.cursor.currentPageIndex * 8) + '</div>');
			});

			$('a.gs-title, div.gs-snippet', gs).each(function() {
				$('b:contains("...")', $(this)).addClass('hellip');
			});

			$('div.gsc-cursor', gs).prepend('Страницы: ');

			$(this).dequeue();
		}).fadeIn('slow');

		$('.jsbanner').show();
	}
	else {
		$('#gs-noresults').show();
	}
}

$(document).ready(function() {
	if ('undefined' != typeof window.searchControl) {
		$('#searchform').submit(function() {
			window.searchControl.execute($('#search-keyword').attr('value'));
			return false;
		});
	}
});

(function() {
	var match = window.location.search.match(/search=([^&#]+)/);
	window.searchTerm = (match) ? decodeURIComponent(match[1]) : null;
})();

