﻿Event.onDOMReady(function()
{
	if ($("accordion"))
	{
		accordion.initialize("accordion", "a.local", "div.accord-slide");
	}
	autorun();
});

function autorun() {
	if (clientIP!="80.237.26.27") {
		flash();
	}
	text_menu();
	externalLinks();
	subscribe();
	jumps();
}

accordion = 
{
	// object
	instance: null,
	
	// elements
	element: null,
	togglers: null,
	stretchers: null,
	
	// properties
	active: null,
	
	initialize: function(element, togglers, stretchers)
	{
		accordion.element = element;
		accordion.togglers = $(accordion.element).select(togglers);
		accordion.stretchers = $(accordion.element).select(stretchers);
	
		accordion.instance = new Fx.Accordion(accordion.togglers, accordion.stretchers,
		{
			"opacity": false,
			"width": false,
			"start": false,
			onActive: function(toggler) { accordion._setActive(toggler); },
			onBackground: function(toggler) {}
		});
		
		accordion.instance.showThisHideOpen(selectedTab);
	},
	
	_setActive: function(toggler)
	{
		accordion.togglers.each(function(item)
		{
			item.removeClassName("active");
		});
		toggler.addClassName("active");
	}
}

function subscribe() {
    if (document.getElementById("subscribe-block")) {
        document.getElementById("ctl00_pole_sex_0").onclick = function() {
            document.getElementById("subscribe-block").style.display = "block";
        }
        document.getElementById("ctl00_pole_sex_1").onclick = function() {
            document.getElementById("subscribe-block").style.display = "none";
        }
    }
}

function video(file, w, h) {
	cX=(screen.width-352)/2;
	cY=(screen.height-288)/2;
	if (!w)
		w = 352;
	if (!h) 
		h = 288;
	win = window.open('video.aspx?file='+file+'&w='+w+'&h='+h,'_blank','width='+w+', height='+h+', scrollbars=no, status=no, toolbar=no,left='+cX+',top='+cY+',screenX'+cX+',screenY='+cY);
}

function text_menu() {
	if (document.getElementById('nav-dreaming')) {
		if (menus) {
			if (menus==1)
				document.getElementById('nav-dreaming').className = 'selected';
			if (menus==2)
				document.getElementById('nav-kitten').className = 'selected';
			if (menus==3)
				document.getElementById('nav-about').className = 'selected';
			if (menus==4)
				document.getElementById('nav-breeds').className = 'selected';
			if (menus==5)
				document.getElementById('nav-menu').className = 'selected';
			if (menus==6)
				document.getElementById('nav-amusements').className = 'selected';
		}
	}
}

function flash() {
	var version = deconcept.SWFObjectUtil.getPlayerVersion();
	if (version["major"] >= 6) {
		menu();
		calendar();
		ration_test();
		languages_test();
		index_banners();
		catalog_new();
		flashSign();
		night();
	}
	else {
		document.getElementById('getflash').style.display = 'block';
	}
}

function menu_select(num) {
	if (num==1)
	 window.location = 'dreaming.aspx';
	else if (num==2)
	 window.location = 'kitten.aspx';
	else if (num==3)
	 window.location = 'about.aspx';
	else if (num==4)
	 window.location = 'breeds.aspx';
	else if (num==5)
	 window.location = 'menu.aspx';
	else if (num==6)
	 window.location = 'amusements.aspx';
}

function index_banners() {
	if (document.getElementById("banner-1")) {
		var so = new SWFObject("/banner/2_wiskasCheckBox_295-200.swf", "flash", "295", "200", "6");
		so.addParam("quality", "high");
		so.addParam("wmode", "transparent");
		so.write("banner-1");
	}
	if (document.getElementById("banner-4")) {
		var so = new SWFObject("/images/banner_presents.swf", "flash", "295", "200", "6");
		so.addParam("quality", "high");
		so.addParam("wmode", "transparent");
		so.write("banner-4");
	}
	if (document.getElementById("banner-3")) {
		var so = new SWFObject("/banner/whiskas_hunt2_site_ver7_link.swf", "flash", "650", "200", "6");
		so.addParam("quality", "high");
		so.addParam("wmode", "transparent");
		so.write("banner-3");
	}
	if (document.getElementById("banner-3_new")) {
		var so = new SWFObject("/banner/whiskas_hunt2_site_ver7_link.swf", "flash", "650", "200", "6");
		so.addParam("quality", "high");
		so.addParam("wmode", "transparent");
		so.write("banner-3_new");
	}
	if (document.getElementById("banner-2")) {
		var so = new SWFObject("/banner/banner_right_295x200_07-09-10_v1.swf", "flash", "295", "200", "6");
		so.addParam("quality", "high");
		so.addParam("wmode", "transparent");
		so.write("banner-2");
	}
	if (document.getElementById("banner-5")) {
		var so = new SWFObject("/images/banner_vege_small.swf", "flash", "295", "200", "6");
		so.addParam("quality", "high");
		so.addParam("wmode", "transparent");
		so.write("banner-5");
	}
	if (document.getElementById("banner-6")) {
		var so = new SWFObject("/images/smetanka_8.swf", "flash", "295", "200", "6");
		so.addParam("wmode", "transparent");
		so.write("banner-6");
	}
}

function menu() {
	if (document.getElementById("menu")) {
		var so = new SWFObject("/images/menu.swf", "flash", "741", "105", "6");
		so.addParam("wmode", "transparent");
		if (menus!='undefined')
			so.addVariable("selected_menu", menus);
		so.write("menu");
	}
}

function calendar() {
	if (document.getElementById("flash-kitten-calendar")) {
		var so = new SWFObject("/images/calendar.swf", "flash", "409", "268", "6", "#F5EFE6");
		so.addVariable("selected_period", period);
		so.write("flash-kitten-calendar");
	}
}

function night() {
	if (document.getElementById("night")) {
		var so = new SWFObject("/images/night.swf", "flashNight", "1000", "700", "9", "#000000");
		so.write("night");
	}
}

function flash_promo_close()
{
	$("night").style.display = "none";
	$("body-index").id = "body-index-visible";
	$("wrapper").style.display = "block";
}

function ration_test() {
	if (document.getElementById("menu-ration-test")) {
		var so = new SWFObject("/images/test.swf", "flash", "414", "289", "6", "#F5EFE6");
		so.write("menu-ration-test");
	}
}

function languages_test() {
	if (document.getElementById("about-language-flash")) {
		var so = new SWFObject("/images/lang.swf", "flash", "414", "289", "6", "#F5EFE6");
		so.write("about-language-flash");
	}
}

function catalog_new() {
	if (document.getElementById("flash-premium")) {
		var so = new SWFObject("/images/premium.swf", "flash", "410", "244", "6");
		so.addParam("wmode", "transparent");
		so.write("flash-premium");
	}
	if (document.getElementById("flash-immuno")) {
		var so = new SWFObject("/images/immuno.swf", "flash", "410", "222", "6");
		so.write("flash-immuno");
	}
	if (document.getElementById("flash-cheese")) {
		var so = new SWFObject("/images/cheese.swf", "flash", "410", "341", "6");
		so.write("flash-cheese");
	}
	if (document.getElementById("flash-meal")) {
		var so = new SWFObject("/images/cow3.swf", "flash", "417", "259", "6");
		so.write("flash-meal");
	}
}

function select_language(num) {
	var captions = document.getElementById('languages').getElementsByTagName('div');
	for (i=0; i<captions.length; i++) {
		captions[i].style.display = 'none';
	}
	captions(num-1).style.display = 'block';
}

function test(result) {
	 window.location = 'menu_ration_result' + result + '.aspx';
}

function select_period(period) {
	if (period > 0 && period < 17) {
		window.location = 'kitten_calendar_week' + period + '.aspx';
	}
	if (period > 16 && period < 25) {
		period = period - 12;
		window.location = 'kitten_calendar_month' + period + '.aspx';
	}
}

function popup(url, width, height) {
	cX=(screen.width-width)/2;
	cY=(screen.height-height)/2;
	var win = window.open('','popup','width='+width+', height='+height+', scrollbars=no, left='+cX+',top='+cY+',screenX'+cX+',screenY='+cY);
	win.document.write('<html><body bgcolor="#F5EFE6" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" bottommargin="0" rightmargin="0"><a href="javascript:close();"><img src="'+url+'" border="0" alt="Закрыть окно"></a></body></html>');
}

function popupPic(url) {
	cX=0;
	cY=0;
	var win = window.open('popup.aspx?' + url,'popup','width=80, height=80, scrollbars=no, resizeable=yes, left='+cX+',top='+cY+',screenX'+cX+',screenY='+cY);
}

function rules(url) {
	cX=(screen.width-600)/2;
	cY=(screen.height-400)/2;
	var win = window.open(url,'popup','width=600, height=400, scrollbars=yes, left='+cX+',top='+cY+',screenX'+cX+',screenY='+cY);
}

function allRules() {
	cX=(screen.width-600)/2;
	cY=(screen.height-400)/2;
	var win = window.open('all_rules.aspx','popup','width=600, height=400, scrollbars=yes, left='+cX+',top='+cY+',screenX'+cX+',screenY='+cY);
}

function externalLinks() { 
 if (!document.getElementsByTagName) return; 
 var anchors = document.getElementsByTagName("a"); 
 for (var i=0; i<anchors.length; i++) { 
   var mylink = anchors[i];
   if (mylink.getAttribute("rel") == "external") {
		 //mylink.click = function() { window.open(this.href); return false; };
     mylink.target = "_blank"; 
	 }
 } 
}

function toggle(id) {
    if (document.getElementById(id)) {
        if (document.getElementById(id).style.display=='' || document.getElementById(id).style.display=='none')
            document.getElementById(id).style.display = 'block';
        else
           document.getElementById(id).style.display='none';
    }
}

function jumps() {
	var wrapper = document.getElementById('upload-date');
	if (wrapper) {
		var inputs = wrapper.getElementsByTagName('input');
		var day = inputs[0];
		var month = inputs[1];
		var year = inputs[2];
		
		day.onkeyup = function () {
			var inputs = wrapper.getElementsByTagName('input');
			var month = inputs[1];
			if (this.value.length >= this.maxLength) {
				month.focus();
			}
		}
		day.onfocus = function() {
			this.value='';
		}
		month.onkeyup = function () {
			var inputs = wrapper.getElementsByTagName('input');
			var year = inputs[2];
			if (this.value.length >= this.maxLength) {
				year.focus();
			}
		}
		month.onfocus = function() {
			this.value='';
		}
		year.onfocus = function() {
			this.value='';
		}
	}
}

function feedback() {
	locationstring = "mailto:support@whiskas.ru?subject=%D1%EE%EE%E1%F9%E5%ED%E8%E5 %F1 %F1%E0%E9%F2%E0 Whiskas.ru&body=%D1%EE%EE%E1%F9%E5%ED%E8%E5 %F1 %F1%E0%E9%F2%E0 Whiskas.ru";
	window.location = locationstring;
}

function flashSign() {
	var version = deconcept.SWFObjectUtil.getPlayerVersion();
	if (version["major"] >= 8) {
		if (document.getElementById("flashcontent")) {
			var so = new SWFObject("images/sign_278x148.swf", "flash_obj", "278", "148", "8", "#FFFFFF");
			so.addParam("wmode", "opaque");
			so.write("flashcontent");
		}
	}
	else {
		document.getElementById("getflash").style.display = "block";
	}
}

function talk2flash() {
	var flash_obj = document.getElementById('flash_obj');
	flash_obj.js2flash();
}

var validateInput = null;

function flash2js(input) {
	var sign_obj = document.getElementById('sign_obj_div').firstChild;
	sign_obj.value = input;
	validateInput = input;
	form_submit();
}

function form_submit() {
	//var form_obj = document.getElementById('aspnetForm');
	//form_obj.submit();
	//alert(WebForm_OnSubmit());
}

function validateSign()
{
	//alert(validateInput.length);
	//return false;
}

function disclaimer(param) {
	if (param)
		document.getElementById("disclaimer").style.display = "block";
	else
		document.getElementById("disclaimer").style.display = "none";
}




 