$(function(){
//===addclass===
$("tr:even").addClass("even");
$("tr:odd").addClass("odd");
$("table.iservices td:even").addClass("even");
$("table.iservices td:odd").addClass("odd");



//===form label===
//$("label:has(input)").each(function(){
//	$(this).css({'display':'inline', 'margin-right':'5px', 'font-size':'100%'});
//});

//===button===
$("input:submit").each(function(){
	$(this).css({'font-size':'90%','font-size':'80%','padding':'5px 15px','color':'#111'});
//	$(this).button();
});
$("button, a.button, a.btn").each(function(){
	$(this).css({'font-size':'90%','padding':'1px 4px','color':'#111'});
//	$(this).button();
});
//===buttonset===
$("div.buttonset ").each(function(){
	$(this).buttonset();
});

//===pause function===
$.fn.pause = function(duration) {
	$(this).animate({ dummy: 1 }, duration);
	return this;
};

//===message_brief===
$(".message_brief li").each(function(){
	$(this).addClass("ui-corner-all");
	$(this).fadeTo(0,0.8).pause(1000).fadeOut(1000);
});

//===growl===
$.fn.growl = function(message) {
	$('body').prepend('<ul class="message_brief"></ul>');
	$('.message_brief').prepend('<li>'+message+'</li>');
	$('.message_brief li').addClass("ui-corner-all");
	$('.message_brief').fadeTo(0,0.8).pause(1000).fadeOut(1000);
	return this;
};

//==floatimage margin==
$('#CenterWrapper img').each(function(){
	if($(this).attr('align')=='left'){
		$(this).css({'margin':'0 10px 10px 0','float':'left'});
		$(this).removeAttr('align');
	}else if($(this).attr('align')=='right'){
		$(this).css({'margin':'0 0 10px 10px','float':'right'});
		$(this).removeAttr('align');
	}else if($(this).attr('align')=='center'){
		$(this).css({'margin':'0 10px 10px 10px'});
	}
});

//==== input.rollover ====
$('input.rollover').hover(function(){
	var imgsrc = $(this).attr('src').replace('_df.gif','_ro.gif');
	$(this).attr('src',imgsrc);
	},function(){
	var imgsrc = $(this).attr('src').replace('_ro.gif','_df.gif');
	$(this).attr('src',imgsrc);
});

// ===captionblock===
$('img.fcr').each(function(){
	var captxt = $(this).attr('alt').replace('[/url]','</a>').replace(']','">').replace('[url=','<a class="noicon" href="');
	var capwidth = $(this).attr('width');
	capwidth=capwidth+10;
//		$(this).wrap('<span style="width:'+capwidth+'px;font-size:90%;float:right;margin:0 0 10px 10px;text-align:center;dispay:block;">');
	$(this).wrap('<div style="width:'+capwidth+'px;font-size:90%;float:right;margin:0 0 10px 10px;text-align:center;">');
	$(this).attr('alt','').after('<br />'+captxt);
});

$('img.fcl').each(function(){
	var captxt = $(this).attr('alt').replace('[/url]','</a>').replace(']','">').replace('[url=','<a class="noicon" href="');
	var capwidth = $(this).attr('width');
	capwidth=capwidth+10;
//		$(this).wrap('<span style="width:'+capwidth+'px;font-size:90%;float:left;margin:0 10px 10px 0;text-align:center;dispay:block;">');
	$(this).wrap('<div style="width:'+capwidth+'px;font-size:90%;float:left;margin:0 10px 10px 0;text-align:center;">');
	$(this).attr('alt','').after('<br />'+captxt);
});


$('img.fcc').each(function(){
	var captxt = $(this).attr('alt').replace('[/url]','</a>').replace(']','">').replace('[url=','<a class="noicon" href="');
//		$(this).wrap('<span style="text-align:center;font-size:90%;margin:0 10px 10px 0;clear:both;dispay:block;">');
	$(this).wrap('<div style="text-align:center;font-size:90%;margin:0 10px 10px 0;clear:both;">');
	$(this).attr('alt','').after('<br />'+captxt);
});

// ===lightbox===
$('a.lb').each(function(){
	var capwidth = $(this).find('img').attr('width');
	capwidth=capwidth+10;
	var altx = $(this).find('img').attr('alt');
	var altx = 'enlearge image (to back to press x)' + altx;
	$(this).find('img').attr('alt',altx);
	$(this).lightBox();
});

//=== lightbox block ===
	$('#lightbox a:has(img)').each(function(){
		var altx = $(this).find('img').attr('alt');
		var altx = 'resizeimage:' + altx;
		$(this).find('img').attr('alt',altx);
		$(this).lightBox();
	});

// ===Mainmenu===
	$('#sitemenu li a').each(function(){
		var menuid = 'menu'+($('#sitemenu li a').index(this)+1);
		var alt = $(this).text();
		$(this).empty();
		if($(this).attr('class')=='on'){
			$('<img src="/view/images/sitemenu/'+menuid+'-ro.gif" alt="'+alt+'" />').prependTo(this);
		}else{
			$('<img src="/view/images/sitemenu/'+menuid+'-df.gif" alt="'+alt+'" />').prependTo(this);
		}
		});

	$('#sitemenu li a').hover(function(){
		var imgsrc = $(this).find('img').attr('src').replace(/\-df.(gif|png|jpg|jpeg)$/i,'-ro.$1');
		$(this).find('img').attr('src',imgsrc);
		},function(){
		if($(this).attr('class')=='on'){
		}else{
		var imgsrc = $(this).find('img').attr('src').replace(/-ro\.(gif|png|jpg|jpeg)$/i,'-df.$1');
		$(this).find('img').attr('src',imgsrc);
		}
	});



//==== a.rollover img ====
$('.bt a.on:has(img)').each(function(){
	var imgsrc = $(this).find('img').attr('src').replace(/\.(gif|png|jpg|jpeg)$/i,'-ro\.$1');
	$(this).find('img').attr('src',imgsrc);
	$(this).parent().removeClass('bt');
});

$('.bt a:has(img)').hover(function(){
	var imgsrc = $(this).find('img').attr('src').replace(/([^-][^r][^o]).(gif|png|jpg|jpeg)$/i,'$1-ro\.$2');
	$(this).find('img').attr('src',imgsrc);
	},function(){
	var imgsrc = $(this).find('img').attr('src').replace(/-ro\.(gif|png|jpg|jpeg)$/i,'\.$1');
	$(this).find('img').attr('src',imgsrc);
});

/*
	var loc = window.location.href;
	if(! loc.match('.html')){
		loc=loc.replace('/#pagetop','');
		loc=loc+'/index.html';
	}
	$('#sitemenu a').each(function(){
		if(loc.match($(this).attr('href'))){
			$(this).addClass('on');
		};
	});
*/
});

