var nextim=0;
var totalimg=4
// μενώ
		
var timeout    = 500;
var closetimer = 0;
var ddmenuitem = 0;

function jsddm_open()
{  jsddm_canceltimer();
   jsddm_close();
   ddmenuitem = $(this).find('ul').css('visibility', 'visible');}

function jsddm_close()
{  if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

function jsddm_timer()
{  closetimer = window.setTimeout(jsddm_close, timeout);}

function jsddm_canceltimer()
{  if(closetimer)
   {  window.clearTimeout(closetimer);
	  closetimer = null;}}

var _dtype;
$(document).ready(
	function(){
		//
		
		//document.body.scrollTop
		//
		var i_pref = ''
		var cheme = readCookie('style')
		if (cheme && cheme == 'light') {
			i_pref = '2'
		}
		// μενώ
		$('#jsddm > li').bind('mouseover', jsddm_open)
		$('#jsddm > li').bind('mouseout', jsddm_timer)
		
		document.onclick = jsddm_close;
		
		$("table[border=1]").attr("width", "100%");
		$("table[border=1]").addClass("j-table");
		$("table[border=1] tr").addClass("j-table-even");
		$("table[border=1] tr:even").addClass("j-table-alt");
		$("table[border=1] tr:first-child").attr("class", "j-table-th");
		$("table[border=1] tr:first-child").css({
			marginTop: "20px"
		});
		$("table[border=1]").attr("border", "0");
		
		$("table[border=1] tr:first-child").css({
			marginTop: "20px"
		});
		
		//************************************************/
		
		
		
		
		$("table.det td.c1:parent").parent().css("cursor", "pointer");
		$("table.det td.c1:parent").parent().click(function(){
		
			//$(this).css('border', '1px solid red');
			
			var obj = $(this).next();
			var td = $(this).find("td.c1");
			
			//alert(obj.attr('class'))
			if (obj.css('display')!='none') {
				td.css("background-image", "url(http://www.tarifer.ru/img/" + i_pref + "show.gif)");
				td.css("background-repeat", "no-repeat");
				td.css("background-position", "10px 12px");
			}
			else {
				td.css("background-image", "url(http://www.tarifer.ru/img/" + i_pref + "hide.gif)");
				td.css("background-repeat", "no-repeat");
				td.css("background-position", "10px 12px");
			}
			var _d = obj.css('display')
			obj.css({display:(_d=='none')? _dtype:'none'})
			//obj.toggle()
		})
		
		var row = 100;
		$.each($("tr.def td.c2 table tr td[class]"), function(j, k){
			row += parseInt($(k).css('width'));
		})
		row += 2; 
		var color = "#565b61"
		var cheme = readCookie('style')
		if (cheme && cheme == 'light') {
			color = "#ebebeb"
		}
		//alert($("table.det:eq(1) > tbody > tr:eq(1)"))
		_dtype = $("table.det:eq(1) > tbody > tr:eq(0)").css('display')
		$("table.det:eq(1) > tbody > tr:eq(1)").css({
			display: _dtype
		})
		$("table.det:eq(1) td.c1:first").css("background-image" , "url(http://www.tarifer.ru/img/" + i_pref + "hide.gif)");
		//console.info($("table.det:eq(1)  tr.odd").length)
		/*
		$.each($("table.det:eq(1)"), function(i, n){
			$.each($(n).find("tr"), function(j, k){
			
			
				if (j % 6 > 2) {
					
					
					$(k).css("background", color);
					$(k).find("span.b-span1 span").css("background", color);
					$(k).find("span.b-span2 b").css("background", color);
				}
				
				if (j % 3 == 0) {
					var td = $(k).find("td.c1");
					if (j != 0) {
						td.css("background-image", "url(http://www.tarifer.ru/img/" + i_pref + "show.gif)");
						td.css("background-repeat", "no-repeat");
						td.css("background-position", "10px 12px");
					}else {
						td.css("background-image", "url(http://www.tarifer.ru/img/" + i_pref + "hide.gif)");
						td.css("background-repeat", "no-repeat");
						td.css("background-position", "10px 12px");
					}
				}else if (j % 3 == 2) {
					if (j != 2) {
						$(k).addClass("nodisplaytabletd")
					}
				}
				
			});
			
		});
		*/
		if (row > 0) {
			var table = $("table.det td.c2");
			table.css("background-image", "url(http://www.tarifer.ru/img/ln.gif)");
			table.css("background-repeat", "no-repeat");
			table.css("background-position", "" + (row + 5) + "px 0px");
		}
		//eraseCookie('t_cooie')
		var x = readCookie('t_cooie')
		if (g_no_show_wizard) {
			x = true;
		}
		//if(location.hash=='#test' || show_wizard){
		if (x) {
		
		}
		else {
			wizard()
		}
		//}
		if (location.hash == '#wizard') {
			wizard()
		}
		else 
			if (location.hash == '#light') {
				createCookie('style', 'light')
			}
			else 
				if (location.hash == '#normal') {
					eraseCookie('style')
				}
	});
function wizard(){
	$('body').append("<div id='darkbg'></div>");
		$('#darkbg').css({"opacity":"0","background":"#232d3b","z-index":"4900","position":"absolute","top":"0px","left":"0px","width":$('body').width()+'px',"height":$('body').height()+'px'}).animate({opacity: 0.7}, 'slow', function(){

		$('body').append("<div id='imgzoom'><div style='position:relative;margin:100px auto 0 auto;height:505px;width:705px;'><iframe style='border:2px solid #000; overflow:hidden; width:700px; height:500px' border=0 src='wizard/w_main'></iframe></div></div>");
		$('#imgzoom').css({"position":"absolute","z-index":"5000","top":"0px","left":"0px","width":$('body').width()+'px',"height":$('body').height()+'px'});
		if($.browser.msie && $.browser.version<7){
		//$('#imgzoom a:first').css("margin-left","170px")	
		}
	});
	
}
function init(){

	$('body').append("<div id='darkbg'></div>");
	$('#darkbg').css({"opacity":"0","background":"#232d3b","z-index":"4900","position":"absolute","top":"0px","left":"0px","width":$('body').width()+'px',"height":$('body').height()+'px'}).animate({opacity: 0.9}, 'slow', function(){

		$('body').append("<div id='imgzoom'><div style='position:relative;margin:150px auto 0 auto;height:649px;background:#fff;width:866px;'><div id='imgzoomin' style='padding:5px'></div><a href='#' onClick='getImgPrew(nextim); return false;' style='display:block; float:left;background:#fff url(http://www.tarifer.ru/img/prev.gif) no-repeat 0 0; border:none;height:45px;width:45px;margin-left:350px;'> </a><a href='#' onClick='getImgNext(nextim); return false;' style='display:block; float:left;background:#fff url(http://www.tarifer.ru/img/next.gif) no-repeat 0 0; border:none;height:45px;width:45px;margin-left:50px'></a><a href='#' onClick='closew(); return false;' style='display:block; float:left;background:#fff url(http://www.tarifer.ru/img/close.gif) no-repeat 15px 15px; border:none;height:45px;width:45px;margin-left:320px'></a></div></div>");
		$('#imgzoom').css({"position":"absolute","z-index":"5000","top":"0px","left":"0px","width":$('body').width()+'px',"height":$('body').height()+'px'});
		if($.browser.msie && $.browser.version<7){
		$('#imgzoom a:first').css("margin-left","170px")	
		}
		getImgNext(0)
	});
	
	
}
function close_w(){
	$('#imgzoom').animate({opacity: 'hide'},'slow',function(){$('#darkbg').animate({opacity: 'hide'},'slow',function(){$('#darkbg').remove();})
	$('#imgzoom').remove();
	});
	nextim=0;
	eraseCookie('t_cooie')
	createCookie('t_cooie','not_show')
}

function getImgNext(id){
	  if(nextim+1<totalimg){
		  nextim++;
	  }else{
		  nextim=0
	  }
	if($.browser.msie && $.browser.version<7){
		$("#imgzoomin").html('<img src="http://www.tarifer.ru/img/skin'+id+'.gif" height="579">');
	
	}else{
		$.get("http://www.tarifer.ru/img/skin"+id+".gif", function(data){
			$("#imgzoomin").html('<img src="http://www.tarifer.ru/img/skin'+id+'.gif" height="579">');
		});	
	}
}

function getImgPrew(id){
	  if(nextim-1<0){
		  nextim=totalimg-1
	  }else{
		  nextim--;
	  }
	if($.browser.msie && $.browser.version<7){
		$("#imgzoomin").html('<img src="http://www.tarifer.ru/img/skin'+id+'.gif" height="579">');
	
	}else{
		$.get("http://www.tarifer.ru/img/skin"+id+".gif", function(data){
			$("#imgzoomin").html('<img src="http://www.tarifer.ru/img/skin'+id+'.gif" height="579">');
		});	
	}
}
function sh(arg){
	var	control = $("#"+arg);
	if(control.css('display')!='none'){
		control.slideUp("slow");  
	}else{
		control.slideDown("slow");  
	}
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}