$(document).ready(function(){
	if ($.browser.msie){IEpngFix();};
//
//	var maxWidth = 1280; // max width
//	var minWidth = 1000; // min width
//	var selector = $("#main"); // selector
//
//	var windowWidthTemp = 0;
//	var windowWidth = 0;
//
//
//	if($.browser.msie){
//		mmwidth();
//		$(window).resize(function(){
//								windowWidth = $(window).width();
//								if (windowWidth != windowWidthTemp){
//									windowWidthTemp = windowWidth;mmwidth();
//									}});};
//	function mmwidth(){
//		$(selector).css({width:100+"%"});
//		bodyWidth = $(window).width();
//		if (bodyWidth < minWidth){
//			$(selector).width(minWidth);
//		}else{
//			if (bodyWidth > maxWidth){
//				$(selector).width(maxWidth);
//			}else{
//				$(selector).width(100+"%");
//			}}}

	//png fix for ie
	function IEpngFix(){
		if ($.browser.msie){
			var transparentImage = "/i/tr.gif";
			
			oImg = $("img[src$=.png].png");
			lImg = $("img[src$=.png].png").length;
			
			for (i=0;i<lImg;i++){
				srcImg = $(oImg[i]).attr("src");
				$(oImg[i]).attr({src:transparentImage});
				oImg[i].runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + srcImg + "',sizingMethod='scale')";
				oImg[i].style.display = "inline-block";
			}
		}
	}
	
	
	function scrolltop(){$(".scrolltop").click(function(){$("body").scrollTo("#main", 800); return false;});}
	
	var timeLoading = 5000;
	localHref = window.location.hash;
	if (localHref){
		localHref = localHref.replace("#", "")
		window.location.href= localHref;
	}
	
	inner();
	function inner(playbool){
		var commentTime = 2000;
		var initTime=1000;
		var comments = $("#comment div[id^='comment']");
		var imgs = $("#imghold li[id^='img']");
		var nums = $("#num li[id^='num']");
		var button = $("#button");
		var pos=0;
		var popup = $("#popup div[id^='popup']");
		langs();
		scrolltop();
		IEpngFix();

		function animateInit(){
			if (pos <5){
						$(imgs).hide();
						$(comments).hide();
						$(imgs).hide();
						$(imgs[pos+1]).show();
						$(nums[pos]).show();
						pos++;
					}else{
							$(imgs[pos]).fadeOut(initTime);
							$(imgs[0]).fadeIn(initTime);
							$(innerText).fadeOut(initTime);
							$(button).fadeIn(initTime);
							return false;
					}
			setTimeout(animateInit, initTime);
		}
		
		
		/* $("#button1").click(function(){
							pos = 0;
							$(nums).hide();
							$(popup).hide();
							animateComments();
							return false;
						}); */
		
		function animateComments(){
			if (pos <5){
						$(comments).hide();
						$(imgs).hide();
						$(comments[pos]).show();
						$(imgs[pos+6]).show();
						$(nums[pos]).find(".numimg").show();
						$(nums[pos]).show();
						pos++;
					}else{
							$(comments).hide();
							$(imgs).hide();
							//$(nums).find(".numimg").hide();
							$(imgs[0]).show();
							return false;
					}
			setTimeout(animateComments, commentTime);
		}
			$(nums).click(function(){
					$(popup).hide();
					//$(nums).find(".numimg").hide();
					//$(imgs).hide();
					var thisId;
					thisId = $(this).attr("id");
					thisId = thisId.replace("num", "");
					thisId = thisId * 1;
					for (i=thisId;i>0;i--){
						$(nums[i-1]).find(".numimg").show();
					}
					//alert(thisID);
					$(popup[thisId-1]).show();
					//$(imgs[thisId]).show();
					//$("body").scrollTo( popup[thisId-1], 1000, {offset: {top:-150} });
					return false;
			});
			$(".close").click(function(){
				$(popup).hide();
				$(imgs).hide();
				$(imgs[0]).show();
				//$(nums).find(".numimg").hide();
				return false;
			});
			

			$("#button td[id^=button]").click(function(e){
							e.preventDefault();
							thisID = $(this).attr("id");
							thisID = thisID.replace("button", "slide");
							thisScroll = $("#"+thisID);
							$("body").scrollTo(thisScroll, 800);
						});

		$(nums).hover(
					function(){
							thisID = $(this).attr("id");
							thisEl = $(this);
							thisID = thisID.replace("num","");
							thisID = thisID*1;
							switch (thisID){
								case 1:
									$(thisEl).find(".numb span").css({"top":"-58px"});
								break;
								case 2:
									$(thisEl).find(".numb span").css({"top":"-59px"});
								break;
								case 3:
									$(thisEl).find(".numb span").css({"top":"-60px"});
								break;
								case 4:
									$(thisEl).find(".numb span").css({"top":"-58px"});
								break;
								case 5:
									$(thisEl).find(".numb span").css({"top":"-59px"});
								break;
							}
							//$(imgs).hide();
							//$(imgs[thisID+10]).show();
						},
					function(){
							$(thisEl).find(".numb span").css({"top":"0"});
							//$(imgs).hide();
							//$(imgs[0]).show();
						});
	}
        popupPos();
	$(window).resize(function(){popupPos();});
	function popupPos(){
		var pos1 = new Array(700, 726, 250, -100, -70);
		var pos2 = new Array(616, 616, 250, 0, 0);
		bodyWidth = $("body").width();
		if (bodyWidth > 1150){
			for (i=1; i<=5; i++){
				$("#popup"+i).css({"left":pos1[i-1]});
			}
			$(".tophold").css({"right":-110});
			$(".blockcontact .lang2").width(335);
			$(".texttop").css({"left":-50});
		}else{
			for (i=1; i<=5; i++){
				$("#popup"+i).css({"left":pos2[i-1]})
			}
			$(".tophold").css({"right":0});
			$(".blockcontact .lang2").width(170);
			$(".texttop").css({"left":0});
		}
	}
	function  langs(){
		$(".langmore").click(function(event){ event.preventDefault();});
		$(".langmore").toggle(function(){
										$(".contact").slideDown(600);
									},
							function(){
										$(".contact").slideUp(600);
									}
		);
		$("body").click(function (e) {
			kids =e.target;
			var _a = kids.parentNode;
			while (true){
				_acl = _a.className;
				_atag = _a.tagName;
				if ((_atag &&(_acl=='contact')))break;
				if(!_atag){
						$(".contact").slideUp(600);
					break;
				}
				_a = _a.parentNode;
			}
			//e.preventDefault();
			//return false;
		});
		$(".texttop .close").click(function(){
			$(".texttop").hide();
			return false;
		});
	}


});
