﻿$(document).ready(function(){
	//$('iframe[src$=http]').remove();
	if($.browser.msie){
		$('img[filter]:not(:[src$="blank.gif"])').each(function(){
			var me=$(this);
			var src=me.attr('src');
			var w=me.width();
			var h=me.height();
			//var newimg=new Image();
			//	newimg.src=src;
			//	var ow=newimg.width;
			//	var oh=newimg.height;
			//alert(w+':'+newimg.width+':'+newimg.height);
			//nw=w*(ow/oh);
			//h=w;
			//w=nw;
			if(w>0&&h>0){
				me.removeAttr('filter');
				me.attr({'src':'images/blank.gif'});
				me.css({width:w,height:h,filter:'progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled="true",sizingMethod="scale",src="'+src+'")'});
			};
		});
	};
	$('.search select').each(function(){
		var me=$(this);
		me.hide();
		var selected=me.find('option:selected').text();
		var selectext=$('<font>'+selected+'</font>').appendTo('.search span');
		var list='<ul id="selectlist">';
		$.each(me.find('option'),function(i,v){
			list=list+'<li val='+$(this).val()+'>'+$(this).text()+'</li>'
		});
		list=list+'</ul>';
		var selectlist=$(list).appendTo('body');
		selectext.mouseover(function(){
			var offset=selectext.offset();
			selectlist.css({left:offset.left,top:offset.top}).show().dropShadow({left:1,top:1,blur:1,opacity:0.2});
			selectlist.find('li').click(function(){
				me.find('option:selected').attr('selected',false);
				me.find('option[value='+$(this).attr('val')+']').attr('selected',true);
				$('.search span font').text($(this).text());
				selectlist.hide().removeShadow();
				$('.search input:text').focus();
			})
			.hover(function(){
				$(this).css({background:'#999',color:'#fff'});
			},function(){
				$(this).css({background:'#fff',color:'#666'});
			});
		});
		$('#selectlist').bind('mouseleave',function(){
			selectlist.hide().removeShadow();
		});
	});
	//$('.menu li:not(:first)').before('<li><span class="sep"></span></li>');
	$('.images img').click(function(){
			var me=$(this);
			var showwidth=300;
			var showheight=225;
			var mt=0;
			var src=me.attr('src').replace('product_small','product');
			var w=me.width();
			var h=me.height();
			$('.image img').hide();
			var newimg=new Image();
				newimg.src=src;
				$('.image img').attr('src',src);
				var loadImg=setInterval(function(){
						if(newimg.readyState=='complete'||newimg.complete==true){
							var ow=newimg.width;
							var oh=newimg.height;
							if(oh==ow){
								w=showwidth;
								h=showheight;
							};
							if(ow<showwidth&&oh<showheight){
								w=ow;
								h=oh;
							}else{
								if(oh>ow){
									w=ow*(showheight/oh);
									h=showheight;
								};
								if(ow>oh){
									h=oh*(showwidth/ow);
									w=showwidth;
								};
							};
							if(h<showheight){
								mt=(showheight-h)/2;
							};
							$('.image').attr('img',src).find('img').css({width:w,height:h}).attr({'vspace':mt});
							if(!jQuery.support.opacity)$('.image img').attr('src','images/blank.gif').css({filter:'progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled="true",sizingMethod="scale",src="'+src+'")'});
							$('.image img').fadeIn('slow');
							clearInterval(loadImg);
						};
					},500);
			//$('.image img').attr('src',src);
		});
	$('#guestbook input,#guestbook textarea').focus(function(){
		$(this).css({background:'#fff'});
	}).blur(function(){
		$(this).css({background:'#e0e0e0'});
	});
	$('.images').each(function(){
		$(this).find('img:first').click();
	});
	$('.image').click(function(){
		var src=$(this).attr('img');
		$('<div class="modal"></div>').appendTo('body').css({width:$(document).docWidth(),height:$(document).docHeight()});
		$('<div id="login__window" class="window"><h4><img src="images/close.gif" class="close" width="12" />'+$(this).attr('title')+'</h4><img id="show" src="'+src+'" /></div>').appendTo('body').center();
		$('.window').width($('.window #show').width());
		$('.window .close').click(function(){
			$('.window,.modal').remove();
		});
	});
	/*
	$('.index_content').css({height:1}).show().animate({height:'+=188px'},600,function(){
		$('.marquees').fadeIn('slow',function(){
			checkButton();
			$('img[filter]').each(function(){
				var me=$(this);
				var src=me.attr('src');
				var w=me.width();
				var h=me.height();
				if(w>0&&h>0){
					me.removeAttr('filter');
					me.attr({'src':webroot+'images/blank.gif'});
					me.css({width:w,height:h,filter:'progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled="true",sizingMethod="scale",src="'+src+'")'});
				};
			});
		});
	});
	*/
	$('.language a').click(function(){
		var over=$('.language').css('overflowY');
		$('.language').addClass('langshow');
		if(over=='hidden')return false;
	});
	checkButton=function(){
		var top=$('.movetop');
		var bottom=$('.movebottom');
		var scr=$('.marquees').scrollTop();
		var scrw=$('.marquees div').height()-$('.marquees').height();
		top.css({opacity:1});
		bottom.css({opacity:1});
		if(scr>=scrw){
			top.css({opacity:1});
			bottom.css({opacity:0.3});
		};
		if(scr==0){
			top.css({opacity:0.3});
			bottom.css({opacity:1});
		};
		if(scrw<=0){
			top.css({opacity:0.3});
			bottom.css({opacity:0.3});
		};
	};
	$('.movetop').click(function(){
		$('.marquees').animate({scrollTop:'-=188px'},800,function(){
			checkButton();
		});
	});
	$('.movebottom').click(function(){
		$('.marquees').animate({scrollTop:'+=188px'},800,function(){
			checkButton();
		});
	});
	setInterval(function(){
		if($('.marquees').scrollTop()>=$('.marquees div').height()-$('.marquees').height()){
			$('.marquees').hide().fadeIn('slow').scrollTop(0);
		}else{
			$('.movebottom').click();
		};
	},3000);
	$('.talk').each(function(){
		var ch=parseInt($(document).cliHeight());
		var cw=parseInt($(document).docWidth());
		var th=parseInt($(this).outerHeight());
		var tw=parseInt($(this).outerWidth());
		$(this).css({left:cw-tw,top:ch-th});
		$(window).scroll(function(){
			var top=parseInt($('.talk').css('top'));
			var scrtop=$(window).getScrollTop();
			$('.talk').css({top:scrtop+ch-th});
		});
		$(this).fadeIn('slow').jqDrag('.move');
	});
	$('.class-note').fadeIn('slow',function(){
		var me=$(this);
		var note=setInterval(function(){
			me.fadeOut(600,function(){
				me.fadeIn(600);
			});
		},1200);
		setTimeout(function(){
			clearInterval(note);
		},3600);
		me.find('img').click(function(){
			me.fadeOut();
		});
	});
});