var partsArray = [];
var test = 0;
//var domain = 'http://b.testsite.bz';
//var test_path = '/kobe-lizard/htdocs';
var domain = 'http://www.kobe-lizard.com';
var test_path = '';

function Initialize(){
	chgPath();
	if(partsArray.length > 0){
		getParts();
	}
	setRollOver();
}

function chgPath(area){
	if(test){
		if(area){
			area = area+" ";
		}else{
			area = "";
		}
		$(area+'img').each(function(){
			var src = $(this).attr('src');
			if(src.indexOf(domain) != -1){
				src = src.replace(domain,'');
			}
			if(src.indexOf(test_path) == -1 && src.substr(0,1) == '/'){
				this.src = test_path+src;
			}
		});
		$(area+'input').each(function(){
			var src = $(this).attr('src');
			if(src.indexOf(domain) != -1){
				src = src.replace(domain,'');
			}
			if(src && src.indexOf(test_path) == -1 && src.substr(0,1) == '/'){
				this.src = test_path+src;
			}
		});
		$(area+'link').each(function(){
			if($(this).attr('rel') == 'stylesheet'){
				var href = $(this).attr('href');
				if(href.indexOf(domain) != -1){
					href = href.replace(domain,'');
				}
				if(href.indexOf(test_path) == -1 && href.substr(0,1) == '/'){
					$(this).attr('href',test_path+href);
				}
			}
		});
		$(area+'a').each(function(){
			var href = $(this).attr('href');
			if(href.indexOf(domain) != -1){
				href = href.replace(domain,'');
			}
			if(href.indexOf(test_path) == -1 && href.substr(0,1) == '/'){
				$(this).attr('href',test_path+href);
			}
		});
		$(area+'form').each(function(){
			var action = $(this).attr('action');
			if(action.indexOf(domain) != -1){
				action = action.replace(domain,'');
			}
			if(action.indexOf(test_path) == -1 && action.substr(0,1) == '/'){
				$(this).attr('action',test_path+action);
			}
		});
	}
}

function includeParts(file,id){
	partsArray.push({"id":"#"+id,"file":file});
}

function getParts(){
	var delimiter;
	var path = "";
	if(test){
		path = test_path;
	}
	for(i in partsArray){
		if($(partsArray[i].id).length > 0){
			delimiter = (partsArray[i].file.indexOf("?") == -1)?'?':'&';
			//$(partsArray[i].id).load(path+partsArray[i].file + delimiter + Math.random(),chgPath);
			$.ajax({
				type:"GET",
				parts:partsArray[i],
				url:path+partsArray[i].file + delimiter + Math.random(),
				success:loadSuccess
			});
		}
	}
}

function loadSuccess(data, dataType){
	$(this.parts.id).html(data);
	chgPath(this.parts.id);
}

function puWin(url,width,height){
	if(!width)width = 400;

	if(!height)height = 420;

	window.open(url,"popup","width="+width+",height="+height+"toolbar=no,status=no,menubar=no,resizable=no,scrollbars");
}

function setRollOver(){
	$("img.ro,input.ro").each(function(){
		var src = $(this).attr('src');
		var hover_src;
		if(src.lastIndexOf('_ov.') != -1){
			hover_src = src;
			src = src.replace('_ov.','.');
		}else{
			hover_src = src.replace(/\.(jpg|gif)$/,'_ov.$1');
		}

		$(this).bind('mouseover',function(){
			$(this).attr('src',hover_src);
		});
		$(this).bind('mouseout',function(){
			$(this).attr('src',src)
		});
	});
}

$(Initialize);

