var debug = 0; // 1:YES 0:NO
// change Flash and CSS 
$( function() {
	var uri = location.href;
	var query = ( uri.match(/\?/) )? uri.split("?")[1] : "";
	var siteId;
	var imgPath = "http://img.mag2.com/h/";
	var imgWidth = 544;
	var imgHeight = 70;
	if ( debug ) {
		siteId = ( query == "" )? "car" : query;
		$( "body" ).attr( "id", siteId );
		var title = imgPath + "logo/" + siteId + ".gif";
		var orz = $( ".orz" ).attr( "href" );
		orz += "?" + siteId;
		$( "#title" ).attr( "src", title );
		$( ".orz" ).attr( "href", orz );
	} else {
		siteId = $( "body" ).attr( "id" );
	}
	if ( siteId == "" ){
		return false;
	}
	var swfFile = imgPath + "top/" + siteId + "_head.swf";
	flashcheck( 6, swfFile, "", imgWidth, imgHeight );

	$( "body.link textarea" ).click( function(){
		this.select();
	});

//	var genreId = "#genre-" + siteId;
//	var genreName = $( genreId + " a" ).html();
//	var genreSite = '<strong>' + genreName + '</strong>';
//	$( genreId ).append( genreSite );
//	$( genreId + " a" ).remove();
});

// returns an integer that indicates the major version of the flash player.
function getFlashMajorVersionNN() {
	var plugin = navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin;
	if ( plugin == void(0) ) {
		return;
	}
	var verStr = plugin.description;
	if (verStr == void(0) ) {
		return;
	}
	
	//e.g. Shockwave Flash 7.0 r19
	var major_minor = verStr.split(".");
	if(major_minor == void(0) || major_minor[0] == void(0)){return;}
	
	//major_minor[0] = "Shockwave Flash 7"
	//major_minor[1] = "0 r19"
	var make_app_ver = major_minor[0].split(" ");
	if(make_app_ver == void(0)){
		return;
	}
	
	//make_app_ver[0] = "Shockwave"
	//make_app_ver[1] = "Flash"
	//make_app_ver[2] = "7"
	return parseInt(make_app_ver[make_app_ver.length - 1]);
}

// returns an integer that indicates the major version of the flash player.
// WARNING:
//  This does'nt work on IE/MacOS9. Try getFlashMajorVersionNN().
function getFlashMajorVersionIE() {
	var obj;
	
	//On NN4 try..catch causes a parse error.
	eval('try{obj = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(e){}');
	if(!obj){return;}
	return Math.floor(obj.FlashVersion() / 0x10000);
}

// wrapper function of getFlashMajorVersionNN() and getFlashMajorVersionIE()
function getFlashMajorVersion() {
	if(navigator != void(0) && navigator.mimeTypes != void(0)
			&& navigator.mimeTypes["application/x-shockwave-flash"] != void(0)){
		return getFlashMajorVersionNN();
	}else if(document.all){
		return getFlashMajorVersionIE();
	}
	return;
}

//arguments:
// reqver   a requested version of the flash player.
// swffile  a file name of the flash movie file.
// imgfile  a file name of the image file which is shown instead of swffile.
// width    the width of swffile and imgfile.
// height   the height of swffile and imgfile.
//description:
// if the version of the flash player is greater than or equal to reqver,
// swffile is shown. Otherwise, imgfile is shown.
function flashcheck(reqver, swffile, imgfile, width, height) {
	var ver = getFlashMajorVersion();
	var htmlFlash = "";
	if(ver != void(0) && ver >= reqver){
		var codebase = 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+reqver+',0,0,0';
		
		htmlFlash += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="'+codebase+'" width="'+width+'" height="'+height+'">';
		htmlFlash += '	<param name="movie" value="'+swffile+'" />';
		htmlFlash += '	<param name="quality" value="high" />';
		htmlFlash += '	<embed src="'+swffile+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'" menu="false"></embed>';
		htmlFlash += '</object>';
	}else{
		htmlFlash += '<img src="'+imgfile+'" width="'+width+'" height="'+height+'" />';
	}
	$( "#logo-obj" ).prepend( htmlFlash );
	return;
}
