/**
 * @author Mikhail A Kozlov
 */
	var curritem=0;
	var newsitems = $("#rotation li").size();
	setInterval(ticknews,6000); //time in milliseconds
$(document).ready(function(){
$(function(){
    $("ul.dropdown li").hover(function(){
        $(this).addClass("hover");
        $('ul:first',this).css('visibility', 'visible');
    }, function(){
        $(this).removeClass("hover");
        $('ul:first',this).css('visibility', 'hidden');
    });
    $("ul.dropdown li ul li:has(ul)").find("a:first").append(" &raquo; ");
});

	$("#maillist_join").live("click",function(){
		$res = $(this);
		$(this).val("Loading...").attr("disabled","disabled");
		var data = $("#maillist").serialize();
		$.getJSON("/_postup.php?Show=Subscribe&ToDo=Visitor",data,function(r){
			if(parseInt(r.res) == 1){
				$("#maillist input:text").val('');
				$res.prev().text(r.msg);
			}else{
				$res.prev().text(r.msg);
			}
			$res.val("Join").removeAttr("disabled");
		});
	});
	$(".msg").live("click",function(){
		$(this).fadeOut("slow",function(){
			$(this).remove();
		});
	});
	$(".inputRed").live("click", function(){
		$(this).removeClass("inputRed");
	});
	$("body").css({'background-attachment' : 'fixed', 'background-position':'top', 'background-repeat':'no-repeat'});
//	$("#container").css('opacity', 0.90);	
	if(screen.width <= 1024){
	document.body.style.backgroundImage="url(/images/imagesNew/bg_1024.jpg)";
	}
	else if(screen.width <= 1280){
	document.body.style.backgroundImage="url(/images/imagesNew/bg_1280.jpg)";
	}
	else if(screen.width <= 1440){
	document.body.style.backgroundImage="url(/images/imagesNew/bg_1440.jpg)";
	}
	else if(screen.width <= 1600){
	document.body.style.backgroundImage="url(/images/imagesNew/bg_1600.jpg)";
	}
	else if(screen.width <= 1900){
	document.body.style.backgroundImage="url(/images/imagesNew/bg_1900.jpg)";
	}

	$("#eMailThis").live('click',function(){
		$("#dialog").load(this.href,{"ToDo":"Form"},function(){
			$("#dialog").dialog({
				title:"Send Link To A Friend",
				width:600,
				height:350,
				buttons: { 
					"Cancel": function(){
						$(this).dialog("close");
					},
					"Send": function(){
						$.getJSON("/_share/send_link.php",$("#dialog form").serializeArray(),function(d){
							if(d.result == 1){
								$("#dialog").dialog("close");
								alert("Sent!");
							}else{
								alert("Error! Please make sure that you've entered both e-mail addresses.");
							}
						});
					}
	
				}			
			}).dialog("open");
		})
		return false;
	});
	$(".ToolTipAjax").click(function(){
		return false;
	});
	$("#info").mouseleave(function(){
		$(this).fadeOut(200);
	})
	$('.ToolTipAjax').hover(function(e) {
		$caller = $(this);
		$caller.css("cursor","progress");
		$("#info").load(this.href,{},function(){
			$(this).fadeIn(400);
			$caller.css("cursor","pointer");
		});
		$('#info').css('top', e.pageY + +20).css('left', e.pageX -250);
			
	}, function() {
		$('#info').hide().text('');
	});
	
	$('.ToolTipAjax').mousemove(function(e) {
		$('#info').css('top', e.pageY + +20).css('left', e.pageX -250);
	});
	$("select.changeType").live('change',function(){
		$(this).next("input:text").attr("name",$(this).find("option:selected").attr("value"));
	});

});


			function onSubmit(source,req) {
				var flag = true;
				$("input:text, select, textarea").each(function (i) {
					for (x in req){
						minlength = 2;
						if(parseInt($(this).attr("minlength")) > minlength){
							minlength = parseInt($(this).attr("minlength")) - 1;
						}
						if(req[x] == $(this).attr("id") && $(this).val().length < minlength){
							flag=false;
							$(this).addClass("inputRed");
						}
					}
				});
				if(flag){
					return true;
				}
				else{
					alert("Required fields are empty!\nPlease correct fields marked with red border and submit this form again.");
					return false;
				}
				return false;      	
			}
			function resetFrom(){
				$("input:text, textarea").val("");
			}

	function NewWindow(mypage,myname,w,h,scroll,pos){
		if(pos=="random"){
			LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;
		}
		if(pos=="center"){
			LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
		else if((pos!="center" && pos!="random") || pos==null){
			LeftPosition=0;TopPosition=20
		}
		settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=yes,status=no,menubar=no,toolbar=no,resizable=no';
		win=window.open(mypage,myname,settings);
	}

	
	function goBack(t){ // guest services subform to immulate go back effect.
		$("#goBack").submit();
	}

	function roundNumber(number,decimal_points) {
		if(!decimal_points) return Math.round(number);
		if(number == 0) {
			var decimals = "";
			for(var i=0;i<decimal_points;i++) decimals += "0";
			return "0."+decimals;
		}
	
		var exponent = Math.pow(10,decimal_points);
		var num = Math.round((number * exponent)).toString();
		return num.slice(0,-1*decimal_points) + "." + num.slice(-1*decimal_points)
	}
	function gloablError(res,msg){
		$(".system_messages").remove();
		var id = 'msg_id_'+ parseInt(Math.random() * 1000);
		var sClass = '';
		switch(res){
			case 0:
				sClass = 'red';
			break;
			case 1:
				sClass = 'green';
			break;
			case 2:
				sClass = 'yellow';
			break;
			case 3:
				sClass = 'blue';
			break;
			case 4:
				sClass = 'white';
			break;
			default:
			  	sClass = 'green';
			break;
		}
		var html = '<div class="grid_16 system_messages '+sClass+'" id="'+id+'"><span class="ico"></span><strong class="system_title">'+msg+'</strong></div><div class="clear">&nbsp;</div>';
		$("#maincontent").prepend(html);
		$(id).slideDown(200);
		id ='#'+id;
		setTimeout("hideMsg('"+id+"')",2000);
	}	
	function hideMsg(id){
		$(id).slideUp(200, function(){
			$(this).remove();
		})
	}
function ticknews() {
	var $img = $("#rotation li:eq("+curritem+") img");
	curritem = ++curritem%newsitems;
	$("#rotation span img").fadeOut("slow", function(){
		$("#rotation span img").attr('src',$img.attr('src')).fadeIn("slow");
	});
}	
