/*
   name - name of the cookie
   value - value of the cookie
   [expires] - expiration date of the cookie
     (defaults to end of current session)
   [path] - path for which the cookie is valid
     (defaults to path of calling document)
   [domain] - domain for which the cookie is valid
     (defaults to domain of calling document)
   [secure] - Boolean value indicating if the cookie transmission requires
     a secure transmission
   * an argument defaults when it is assigned null as a placeholder
   * a null placeholder is not required for trailing omitted arguments
*/

function setCookie(name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
	document.cookie = curCookie;
}


/*
  name - name of the desired cookie
  return string containing value of specified cookie or null
  if cookie does not exist
*/

function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
	if (begin != 0) return null;
	}
	else
		begin += 2;
	var end = document.cookie.indexOf(";", begin);
	if (end == -1)
		end = dc.length;
	return unescape(dc.substring(begin + prefix.length, end));
}


/*
   name - name of the cookie
   [path] - path of the cookie (must be same as path used to create cookie)
   [domain] - domain of the cookie (must be same as domain used to
     create cookie)
   path and domain default if assigned null or omitted if no explicit
     argument proceeds
*/

function deleteCookie(name, path, domain) {
	if (getCookie(name)) {
		document.cookie = name + "=" +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"



// Задаём ширину окна

var hostname = "www.coweb.ru";

function getClientWidth()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}	

function setWidth() {
	var width = getClientWidth();
	if (width > 1280) {
		$("#globalcontainer").css({"width":"1250px"});
	}
	else {
		$("#globalcontainer").css({"width":"auto"});
	}
}

var arVersion = navigator.appVersion.split("MSIE");
var version = parseFloat(arVersion[1]);
function fixPNG(myImage) {
	if ((version >= 5.5) && (version < 7) && (document.body.filters)) {
		var imgID = (myImage.id) ? "id='" + myImage.id + "' " : "";
		var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : "";
		var imgTitle = (myImage.title) ? "title='" + myImage.title + "' " : "title='" + myImage.alt + "' ";
		var imgStyle = "display:inline-block;" + myImage.style.cssText;
		var strNewHTML = "<span " + imgID + imgClass + imgTitle
			+ " style=\"" + "width:" + myImage.width + "px; height:" + myImage.height + "px;" + imgStyle + ";"
			+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			+ "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>";
		myImage.outerHTML = strNewHTML;
	}
}

document.click = function(e) {
  e = e || event;
  var t = e.target || e.srcElement;
  if (t.tagName.toLowerCase() == 'a' && /\bpopup\b/.test(t.className)) {
    window.open(t.href,'','');
    return false;
  }
  return true;
}

function redir() {
	function hasHash() {
		if (document.location.hash == "" )
			return false;
			return true;
	}
	if (hasHash()) {
		var linkmain = 'http://' + hostname + "/" + document.location.hash.replace('#/', '');
		//var linkmain = 'http://' + location.href + "/" + document.location.hash.replace('#/', '');
		//linkmain;
		$.get(linkmain, { encode: "1"},
			function(html){
				$("#main_content #content").html(html);
				$("#main_content #content").prepend("<script type='text/javascript' >$('a.preview').simpletooltip();</script>");
		});
		$.get(linkmain, { encode: "3"},
			function(html){
				$("#main_content .worksheader").html(html);
		});
		$.get(linkmain, { encode: "2"},
			function(html){
				$("#main_content #mainblock").html(html);
		});
		
		var linkCh = 'http://' + hostname + '/';
		var link0 = linkmain;
		var link_end = link0.replace(linkCh, '');
		document.location = linkCh + '#/' + link_end;
	}
}

	// $(".banner").ajaxStart(function(){
		// $(".banner").animate({opacity: 0.1}, 50);
		// $("#center_b").append('<div id="loading"><img src="/images/ajax-loader.gif" alt="loading" ></div>');
	// });
	// $(".banner").ajaxSuccess(function(evt, request, settings){
		// $(".banner").animate({opacity: 1}, 50);
		
	// });
	

$(document).ready(function(){
	setWidth();
	$("a.preview").simpletooltip();
	redir();		
	$(".banner").hide();
	$(".banner:first").show();
	$(".banner:first").addClass("current");
    /*$(".menu1").click(function(){
		$(".menu1").removeClass('active');
		$(this).addClass('active');
		show_h();
		$.get(this.href, { encode: "3"},
			function(html){
				$("#main_content .worksheader").html(html);
		});
		$.get(this.href, { encode: "2"},
			function(html){
				$("#main_content #mainblock").html(html);
		});
		$.get(this.href, { encode: "1"},
			function(html){
				$("#main_content #content").html(html);
				$("#main_content #content").prepend("<script type='text/javascript' >$('a.preview').simpletooltip();</script>");
		});
		var linkCh = 'http://' + hostname + '/';
		var link0 = this.href;
		link1 = link0.replace(linkCh, '');
		document.location = linkCh + '#/' + link1;
		show_s();
		return false;  
    });*/
	$(".tpabr1 a").click(function(){
		$('.banner').animate({left: getClientWidth()}, 700);
		$.get("http://" + hostname + "/", { banner: $(".banner").attr('id'), position: "right"},
		function(html){
			$("#center_b").html(html);
			banner_after1();
		});
		return false		
    });
	$(".tpabl1 a").click(function(){
		$('.banner').animate({left: -getClientWidth()}, 700);
		$.get("http://" + hostname + "/", { banner: $(".banner").attr('id'), position: "left"},
		function(html){
			/*if(getCookie("cowebbanner")) html = getCookie("cowebbanner");
			else setCookie("cowebbanner", html);*/
			$("#center_b").html(html);
			banner_after2();
		});
		return false			
     });
});

function banner_after1() {
	$('.banner').hide();
	$('.banner').animate({left: -getClientWidth()}, 0);
	$('.banner').show();
	$('.banner').animate({left: '0'}, 500);
}

function banner_after2() {
	$('.banner').hide();
	$('.banner').animate({left: getClientWidth()}, 0);
	$('.banner').show();
	$('.banner').animate({left: "0"}, 500);
}

function menu2(link){
	show_h2(); 
	$.get(link, { encode: "3"},
	function(html){
		$("#main_content .worksheader").html(html);
	});
	$.get(link, { encode: "1"},
	function(html){
		$("#main_content #content").html(html);
		$("#main_content #content").prepend("<script type='text/javascript' >$('a.preview').simpletooltip();</script>");
	});
	var linkCh = 'http://' + hostname + '/';
	var link0 = link;
	link1 = link0.replace(linkCh, '');
	document.location = linkCh + '#/' + link1;
	show_s2();	
}

function docs1(link){
	show_h2(); 
	$.get(link, { encode: "3"},
	function(html){
		$("#main_content .worksheader").html(html);
	});
	$.get(link, { encode: "1"},
	function(html){
		$("#main_content #content").html(html);
		$("#main_content #content").prepend("<script type='text/javascript' >$('a.preview').simpletooltip();</script>");
	});
	var linkCh = 'http://' +  hostname + '/';
	var link0 = link;
	link1 = link0.replace(linkCh, '');
	document.location = linkCh + '#/' + link1;
	show_s2();
}				

function show_s() {
	$("#mainblock").animate({left: getClientWidth()}, 0);
	$("#mainblock").animate({left: "0"}, 1000);
	$("#content").animate({left: getClientWidth()}, 0);
	$("#content").animate({left: "0"}, 800);
	$(".worksheader").animate({left: getClientWidth()}, 0);
	$(".worksheader").animate({left: "0"}, 900);
}

function show_s2() {
	$("#content").animate({left: getClientWidth()}, 0);
	$("#content").animate({left: "0"}, 700);
	$(".worksheader").animate({left: getClientWidth()}, 0);
	$(".worksheader").animate({left: "0"}, 800);
}

function show_h2() {
	$("#content").animate({left: -getClientWidth()*2}, 1000);
	$(".worksheader").animate({left: -getClientWidth()*2}, 900);
}

function show_h() {
	$("#mainblock").animate({left: -getClientWidth()-100}, 800);
	$("#content").animate({left: -getClientWidth()-100}, 1000);
	$(".worksheader").animate({left: -getClientWidth()-100}, 900);
}
