var pic_path = "img/";

function ___winSize(){
	var myWidth = 0, winHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		winWidth = window.innerWidth;
		winHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		winWidth = document.documentElement.clientWidth;
		winHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		winWidth = document.body.clientWidth;
		winHeight = document.body.clientHeight;
	}
	arrayWinSize = new Array(winWidth,winHeight);
	return arrayWinSize;
}
function widthFix(){
    ___winSize();
    if(document.getElementById("top_block")){
        if(arrayWinSize[0] <= 1004){
            $("#top_block").css({width:"1004px"}); 
        }
        else{
            $("#top_block").css({width:arrayWinSize[0] + "px"});
        }
    }
    else if(document.getElementById("pro_block")){
        if(arrayWinSize[0] <= 1004){
            $("#pro_block").css({width:"600px"}); 
        }
        else{
            $("#pro_block").css({width:arrayWinSize[0] + "px"});
        }    
    }
}
function heightFix(){
    var rubber = $("#share");
    rubber.css({height:"auto"});
    ___winSize();
    var pageHeight = $("#heighter").height();
    if(pageHeight < arrayWinSize[1]){
        rubber.css({height:arrayWinSize[1] - 73 + "px"});
    }
    else{
        rubber.css({height:pageHeight + "px"});
    }
}
function show_popup(elem){
    $(".bubles").css({display:"none"});
    $("#" + elem).css({display:"block"});
}

function expertBox(){
    if(document.getElementById("expert_line")){
        var expertLineWidth = parseInt(document.getElementById("expert_line").offsetWidth);
        if(expertLineWidth <= 905){
            $("#left_step, #right_step").css({display:"none"});
        }
        var qExpert = parseInt(expertLineWidth / 130);
        var expertLimit = -(qExpert - 8) * 130;
        arrayExpertLine = new Array(expertLineWidth,qExpert,expertLimit);
        return arrayExpertLine;
    }
}

var ex_step = 130;
function expertScroll(path){
    currentPosition = parseInt(document.getElementById("expert_line").style.marginLeft);
    if(!currentPosition){
		currentPosition = 0;
	}
    if(path == "back"){
        if(currentPosition == 0){
            return false;
        }
        $("#expert_line").animate({marginLeft:currentPosition + ex_step + "px"}, 500);
        if(currentPosition == -ex_step){
            $("#left_step").attr({ src:pic_path + "back_gray.gif"});
        }
        $("#right_step").attr({ src:pic_path + "strelka_brown_right.gif"});
    }
    if(path == "forward"){
        if(currentPosition < arrayExpertLine[2]){
            return false;
        }
        if(currentPosition == arrayExpertLine[2]){
            $("#right_step").attr({ src:pic_path + "fwd_gray.gif"});
        }
        $("#expert_line").animate({marginLeft:currentPosition - ex_step + "px"}, 500);
        $("#left_step").attr({ src:pic_path + "strelka_brown_left.gif"});
    }
}


var input_text = "Название вашей темы";
var input_att = "Добавить код видео или вставить фото";
var textarea_text = "Текст";
var textarea_add = "Впишите название (не больше 32 символов)";
var scroll_step = 310;
var sh_step = 78;
var map_path = "img/map/";

function textareaClick(object) 
{
    var valueF = object.value;
    if(valueF == "" || valueF == "Напишите, пожалуйста, текст вашего ответа в этом окне"){        
        object.value = '';
        object.style.color='#000';
    }
};

$(document).ready(function(){
    jQuery.each(jQuery.browser, function(i) {
    	if($.browser.msie){
            widthFix();
            $(".select_lang *:first-child")
                .css({ borderLeft:"0px", padding:"1px 5px 1px 0"});
            $(".navigation a:first-child, .navigation strong:first-child")
                .css({marginLeft:"0"});
            $(".profile_headers div:first-child")
                .css({borderLeft:"0", padding:"0 15px 0 0"});
        }
	});
    $("#passwd_text").css({display:"block"});
    $("#passwd_text").click(function(){
        var paaswdPool = $("#passwd_body");
        $(this).css({display:"none"});
        paaswdPool.focus();
    });
    $("#passwd_body").focus(function(){
         $("#passwd_text").css({display:"none"});
    });
    $("#passwd_body").blur(function(){
        var para = $(this).attr('value');
        if( para == ""){
            $("#passwd_text").css({display:"block"});
        }
    });
    var linkBox = $(".abs_link");
    $("area").mouseover(
        function(){
            linkBox.css({display:"none"});
            var target = $(this).attr("name");
            $("#" + target).css({display:"block"});
        }
    );
    $(".str_hover > a").hover(
        function(){
            $(this).attr({id:"over"});
            $("#over img").attr({src: pic_path + "str_gray.gif"});
        },
        function(){
            $("#over img").attr({src: pic_path + "str_yellow.gif"});
            $(this).attr({id:""});
        }
    );
    linkBox.hover(
        function(){
            $(this).css({display:"block"});
        },
        function(){
            $(this).css({display:"none"});
        }
    );
    $(".abs_picture").mouseout(
        function(){
            $(".abs_link").css({display:"none"});
        }
    );
    $("#name_konkurs").hover(
        function(){
            $(this).css({ color:"#666666"});
        },
        function(){
            $(this).css({ color:"#ED145B"});
        });
    $("#ex_close").click(function(){
        $("#sh_up").css({display:"none"});
    });
    $("#best_topic div:first-child").css({margin:"0"});
    $("#post_title").click(function(){
        if(this.value == input_text){
            this.value = "";
            $(this).css({color:"#000"});
        }
    });
    $("#post_title").blur(function(){
        if(this.value == ""){
            $(this).css({color:"#898989"});
            this.value = input_text;
        }
    });
    $("#post_attach").click(function(){
        if(this.value == input_att){
            this.value = "";
            $(this).css({color:"#000"});
        }
    });
    $("#post_attach").blur(function(){
        if(this.value == ""){
            $(this).css({color:"#898989"});
            this.value = input_att;
        }
    });
    $("#post_body").click(function(){
        if(this.value == textarea_text){
            this.value = "";
            $(this).css({color:"#000"});
        }
    });
    $("#post_body").blur(function(){
        if(this.value == ""){
            $(this).css({color:"#898989"});
            this.value = textarea_text;
        }
    });
    $("#name_photo").click(function(){
        if(this.value == textarea_add){
            this.value = "";
            $(this).css({color:"#000", fontSize:"14px"});
        }
    });
    $("#name_photo").blur(function(){
        if(this.value == ""){
            $(this).css({color:"#898989", fontSize:"12px"});
            this.value = textarea_add;
        }
    });
    $(".change_image").click(function(){
        var big_picture = $("#placent_image");
        var status = $(this).attr("id");
        if(status == "ctv"){return false;}
        var img_target = $(this).attr("href");
        big_picture.css({display:"none"}).attr({src:img_target}).fadeIn("normal");
        $("#ctv").attr({id:""});
        $(this).attr({id:"ctv"});
        return false;
    });
	/*$(".sham_slot a").click(function(){
		var chekpoint = $(this).parent().attr("id");
		if(chekpoint == "act_current"){return false;}
		var _img_target_ = $(this).attr("href");
		var bookmark = $(this).attr("name");
		$(".book_marks span").css({width:"18px"});
		$("#" + bookmark).css({width:"auto"});
		$("#sh_image").css({display:"none"}).attr({src:_img_target_}).fadeIn("slow");
		$("#act_current").attr({id:""});
		$(this).parent().attr({id:"act_current"});
        this.blur();
		return false;
	});*/
    $("#back_step, #fwd_step").mouseover(
        function(){
            var noctl = $(this).attr("src")
            if(noctl.lastIndexOf("black")>=0){
                $(this).css({cursor:"pointer"});
            }else{
                $(this).css({cursor:"default"});
            }
        }
    );
    $("#right_step, #left_step").mouseover(
        function(){
            var noctl = $(this).attr("src")
            if(noctl.lastIndexOf("brown")>=0){
                $(this).css({cursor:"pointer"});
            }else{
                $(this).css({cursor:"default"});
            }
        }
    );
    /*$(".book_marks a").click(function(){
        var chekpoint = $(this).attr("id");
		if(chekpoint == "sh_current"){this.blur();return false;}
        var __target__ = $(this).attr("href");
        $("#sh_current").attr({id:""}).css({marginLeft:""});
        //$(this).attr({id:"sh_current"}).animate({marginLeft:"-100px"}, 300);
        $("#sh_image").css({display:"none"}).attr({src:__target__}).fadeIn("slow");
        this.blur();
        //return false;
    });*/
    $("#gotoex").hover(
        function(){
            $("#gotoex img").attr({src:"img/korona_big_.gif"});
        },
        function(){
            $("#gotoex img").attr({src:"img/korona_big.gif"});
        }
    );
    expertBox();
    $("#ukraine area").hover(
        function(){
            target = $(this).attr("name");
            $(".map_box").attr({id:target});
        },
        function(){
            $(".map_box").attr({id:""});
        }
    );
    /*$("#ukraine area").click(function(){
        target = $(this).attr("name");
        if(document.getElementById("current_city")){
            $("#current_city").attr({id:""});
        }
        $("#active_city").attr({ src:map_path + target + ".gif" });
        $("." + target).attr({ id:"current_city" });
        return false;
    });*/
    //$(".bubles").click(function(){
    //    alert("start");
    //});
});

function scroll_one(direction){
	var scroll_line = $("#scroll_line");
	var current_pos = parseInt(document.getElementById("scroll_line").style.marginLeft);
	if(!current_pos){
		current_pos = 0;
	}
	if(direction == "fwd" && current_pos == 0){
		$("#fwd_step").attr({src:"img/fwd_gray.gif"});
	}
	else if(direction == "back" && current_pos == -310){
		$("#back_step").attr({src:"img/back_gray.gif"});
	}
	if(direction == "fwd" && current_pos >= 0){
		scroll_line.animate({marginLeft:current_pos - scroll_step + "px"}, 1000);
		$("#back_step").attr({src:"img/back_black.gif"});
	}
	else if(direction == "back" && current_pos <= -310){
		scroll_line.animate({marginLeft:current_pos + scroll_step + "px"}, 1000);
		$("#fwd_step").attr({src:"img/fwd_black.gif"});
	}
	
}

function scroll_two(direction){
	var scroll_line = $("#sham_line");
	var current_pos = parseInt(document.getElementById("sham_line").style.marginLeft);
	if(!current_pos){
		current_pos = 0;
	}
	if(direction == "fwd" && current_pos == 0){
		$("#fwd_step").attr({src:"img/fwd_gray.gif"});
	}
	else if(direction == "back" && current_pos == -78){
		$("#back_step").attr({src:"img/back_gray.gif"});
	}
	if(direction == "fwd" && current_pos >= 0){
		scroll_line.animate({marginLeft:current_pos - sh_step + "px"}, 500);
		$("#back_step").attr({src:"img/back_black.gif"});
	}
	else if(direction == "back" && current_pos <= -78){
		scroll_line.animate({marginLeft:current_pos + sh_step + "px"}, 500);
		$("#fwd_step").attr({src:"img/fwd_black.gif"});
	}
	
}

function checkform(data){
    var valueF = $("#" + data).attr('value');
    x=/[A-Za-z0-9А-Яа-я]/;
    if(!valueF.match(x)){
        $("#" + data).css({color:"red"}).attr({ value: "Напишите, пожалуйста, текст вашего ответа в этом окне" });
    }
}


$(document).mousedown(function(ev){
    var ev = ev || window.event;
    var target = ev.target || ev.srcElement;
    if(target.className != "bubles"){
        if(target.nodeName != "A"){
            $(".bubles").css({display:"none"});
        }
    }
});
$(window).resize(function(){
    jQuery.each(jQuery.browser, function(i) {
    	if($.browser.msie){
            widthFix(); 
        }
    });
   // heightFix();
});


	

