﻿var banner1_show = 0;
var banner2_show = 0;
var banner3_show = 0;
var banner4_show = 0;
function ScoreAllBanners () {
	request.open ( "POST", "/includes/ajax-banner.php", true );
	request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");	
 	request.onreadystatechange = Show1;
	var params = '';
	if ( typeof ( banners1[0] ) != 'undefined' && typeof ( banners1[0][4] ) != 'undefined' )
		params += "banner1_id=" + banners1[0][4] + "&has_showed1=" + banners1[0][5];
	if ( typeof ( banners2[0] ) != 'undefined' && typeof ( banners2[0][4] ) != 'undefined' )
		params += "&banner2_id=" + banners2[0][4] + "&has_showed2=" + banners2[0][5];
	if ( typeof ( banners3[0] ) != 'undefined' && typeof ( banners3[0][4] ) != 'undefined' )
		params += "&banner3_id=" + banners3[0][4] + "&has_showed3=" + banners3[0][5];
	if ( typeof ( banners4[0] ) != 'undefined' && typeof ( banners4[0][4] ) != 'undefined' )
		params += "&banner4_id=" + banners4[0][4] + "&has_showed4=" + banners4[0][5];
	//alert ( banner_id );	
    request.send( params );	
}
function ScoreMainBanners () {
	request.open ( "POST", "/includes/ajax-banner.php", true );
	request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");	
 	request.onreadystatechange = Show1;
	var params = '';
	if ( typeof ( banners1[0] ) != 'undefined' && typeof ( banners1[0][4] ) != 'undefined' )
		params += "banner1_id=" + banners1[0][4] + "&has_showed1=" + banners1[0][5];
	if ( typeof ( banners2[0] ) != 'undefined' && typeof ( banners2[0][4] ) != 'undefined' )
		params += "&banner2_id=" + banners2[0][4] + "&has_showed2=" + banners2[0][5];	
	if ( typeof ( banners4[0] ) != 'undefined' && typeof ( banners4[0][4] ) != 'undefined' )
		params += "&banner4_id=" + banners4[0][4] + "&has_showed4=" + banners4[0][5];
	//alert ( banner_id );	
    request.send( params );	
}
function ScoreBanner ( banner_id, has_showed ) {
	request.open ( "POST", "/includes/ajax-banner.php", true );
	request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");	
 	request.onreadystatechange = Show1;
	var params = "banner_id=" + banner_id + "&has_showed=" + has_showed;
	//alert ( banner_id );
    request.send( params );	
}
function Show1 () {
     if (request.readyState == 4) {
	 	if (request.status == 200) {
		 	var val = request.responseText;			
			//alert ( val );
		}
		else {
			//alert("status is " + request.status);
		}
	 }
}
function FadeOut ( elem, id_img, level, st ) {
	elem.style.opacity = (level - 0.05);
	var level_val = level * 100;	
	elem.style.filter = 'alpha(opacity='+ level_val + ')';
//	var im = document.getElementById ( id_img );
//	if ( im )
//		im.style.filter = 'alpha(opacity='+ level_val + ')';
	if ( level > 0.05 )
		setTimeout ( function() { FadeOut ( elem, id_img, level - 0.05, st ) }, 50 );
	else if ( level == 0.05 )
		setTimeout ( function() { FadeOut ( elem, id_img, level - 0.05, st ) }, 1000 );
	else 
		ChangeElem ( elem, id_img, st );
}
function FadeIn ( elem, id_img, level ) {
	elem.style.opacity = (level + 0.05);
	var level_val = level * 100;
	elem.style.filter = 'alpha(opacity='+ level_val + ')';
//	var im = document.getElementById ( id_img );
//	if ( im )
//		im.style.filter = 'alpha(opacity='+ level_val + ')';	
	if ( level <= 0.95 )
		setTimeout ( function() { FadeIn ( elem, id_img, level + 0.05 ) }, 100 );
}
function ChangeElem ( elem, id_img, st ) {
	elem.innerHTML = st;
	FadeIn ( elem, id_img, 0 );
}
function ChangeBanner1 ( index, count ) {
	if ( count <= 0 ) return;		
	var banner_div = document.getElementById ( 'banner1' );
	if ( !banner_div ) return;

	banner1_show++;
	if ( index >= count ) index = 0;
	else if ( index < 0 ) index = 0;
	var image = banners1[index][0];
	var st;
	if ( image.match ( 'swf' ) ) {
		//file_name = image.substr ( 0, image.length-4 );
		file_name = image;		
		st = '<object id="ban_img1" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="100%" height="100%"><param name="movie" VALUE="' + file_name + '"><param name="wmode" value="transparent"><param name="quality" value="high"><param name="flashvars" value="url='+banners1[index][2]+'"><embed id="ban_img1" src="' + file_name + '" width="100%" height="100%" type="application/x-shockwave-flash" flashvars="url='+banners1[index][2]+'" wmode="transparent" quality="high"></embed></object>';
		//if ( flashVersion() ) {
		//	st = AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0', 'width', '100%','height', '100', 'src', file_name,'quality','high', 'pluginspage','http://www.macromedia.com/go/getflashplayer','movie', file_name, 'wmode', 'transparent', 'flashvars', 'url='+banners1[index][2] );
			//alert ( st );
		//}
	}
	else
		if ( banners1[index][2] )
			st = '<a href="' + banners1[index][2] + '" title="' + banners1[index][3] + '" target="_blank"/><img src="' + banners1[index][0] + '" border="0" id="ban_img1"  /></a>';
		else
			st = '<img src="' + banners1[index][0] + '" border="0" id="ban_img1" />';	
	if ( banner1_show > 1 ) {
		FadeOut ( banner_div, 'ban_img1', 1, st );
		if ( banner1_show <= count )		
			ScoreBanner ( banners1[index][4], banners1[index][5] );
	}
	else
		banner_div.innerHTML = st;
	//FadeIn ( document.getElementById ( 'banner1' ), 0 );
	if ( count > 1 )
		setTimeout ( function() { ChangeBanner1 ( index+1, count ) }, banners1[index][1]*1000 );
}
function ChangeBanner2 ( index, count ) {
	if ( count <= 0 ) return;		
	var banner_div = document.getElementById ( 'banner2' );
	if ( !banner_div ) return;

	banner2_show++;
	if ( index >= count ) index = 0;
	else if ( index < 0 ) index = 0;
	var image = banners2[index][0];
	var st;
	if ( image.match ( 'swf' ) ) {
		//file_name = image.substr ( 0, image.length-4 );
		file_name = image;
		st = '<object id="ban_img2" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="100%" height="100%"><param name="movie" VALUE="' + file_name + '"><param name="wmode" value="transparent"><param name="quality" value="high"><param name="flashvars" value="url='+banners2[index][2]+'"><embed id="ban_img2" src="' + file_name + '" width="100%" height="100%" type="application/x-shockwave-flash" flashvars="url='+banners2[index][2]+'" wmode="transparent" quality="high"></embed></object>';
		//if ( flashVersion() )
		//	st = AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0', 'width', '320','height', '280', 'src', file_name,'quality','high', 'pluginspage','http://www.macromedia.com/go/getflashplayer','movie', file_name, 'wmode', 'transparent', 'flashvars', 'url='+banners2[index][2] );
	}
	else
		if ( banners2[index][2] )
			st = '<a href="' + banners2[index][2] + '" title="' + banners2[index][3] + '" target="_blank"/><img src="' + banners2[index][0] + '" border="0" id="ban_img2"  /></a>';
		else
			st = '<img src="' + banners2[index][0] + '" border="0" id="ban_img2" />';
	if ( banner2_show > 1 ) {
		FadeOut ( banner_div, 'ban_img2', 1, st );
		if ( banner2_show <= count )		
			ScoreBanner ( banners2[index][4], banners2[index][5] );
	}
	else
		banner_div.innerHTML = st;
	//FadeIn ( document.getElementById ( 'banner1' ), 0 );
	if ( count > 1 )
		setTimeout ( function() { ChangeBanner2 ( index+1, count ) }, banners2[index][1]*1000 );
}
function ChangeBanner3 ( index, count ) {
	if ( count <= 0 ) return;		
	var banner_div = document.getElementById ( 'banner3' );
	if ( !banner_div ) return;

	banner3_show++;
	if ( index >= count ) index = 0;
	else if ( index < 0 ) index = 0;
	var image = banners3[index][0];
	var st;
	if ( image.match ( 'swf' ) ) {
		//file_name = image.substr ( 0, image.length-4 );
		file_name = image;
		st = '<object id="ban_img3" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="100%" height="100%"><param name="movie" VALUE="' + file_name + '"><param name="wmode" value="transparent"><param name="quality" value="high"><param name="flashvars" value="url='+banners3[index][2]+'"><embed id="ban_img3" src="' + file_name + '" width="100%" height="100%" type="application/x-shockwave-flash" flashvars="url='+banners3[index][2]+'" wmode="transparent" quality="high"></embed></object>';
		//if ( flashVersion() )
		//	st = AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0', 'width', '320','height', '140', 'src', file_name,'quality','high', 'pluginspage','http://www.macromedia.com/go/getflashplayer','movie', file_name, 'wmode', 'transparent', 'flashvars', 'url='+banners3[index][2] );
	}
	else
		if ( banners3[index][2] )
			st = '<a href="' + banners3[index][2] + '" title="' + banners3[index][3] + '" target="_blank"/><img src="' + banners3[index][0] + '" border="0" id="ban_img3"  /></a>';
		else
			st = '<img src="' + banners3[index][0] + '" border="0" id="ban_img3" />';	
	if ( banner3_show > 1 ) {
		FadeOut ( banner_div, 'ban_img3', 1, st );
		if ( banner3_show <= count )		
			ScoreBanner ( banners3[index][4], banners3[index][5] );
	}
	else
		banner_div.innerHTML = st;
	//FadeIn ( document.getElementById ( 'banner1' ), 0 );
	if ( count > 1 )
		setTimeout ( function() { ChangeBanner3 ( index+1, count ) }, banners3[index][1]*1000 );
}
function ChangeBanner4 ( index, count ) {
	if ( count <= 0 ) return;		
	var banner_div = document.getElementById ( 'banner4' );
	if ( !banner_div ) return;

	banner4_show++;
	if ( index >= count ) index = 0;
	else if ( index < 0 ) index = 0;
	var image = banners4[index][0];
	var st;
	if ( image.match ( 'swf' ) ) {
		//file_name = image.substr ( 0, image.length-4 );
		file_name = image;
		//alert ( file_name );
		st = '<object id="ban_img4" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="100%" height="100%"><param name="movie" VALUE="' + file_name + '"><param name="wmode" value="transparent"><param name="quality" value="high"><param name="flashvars" value="url='+banners4[index][2]+'"><embed id="ban_img4" src="' + file_name + '" width="100%" height="100%" type="application/x-shockwave-flash" flashvars="url='+banners4[index][2]+'" wmode="transparent" quality="high"></embed></object>';
		//if ( flashVersion() )
		//	st = AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0', 'width', '100%','height', '100', 'src', file_name,'quality','high', 'pluginspage','http://www.macromedia.com/go/getflashplayer','movie', file_name, 'wmode', 'transparent', 'flashvars', 'url='+banners4[index][2] );
	}
	else
		if ( banners4[index][2] )
			st = '<a href="' + banners4[index][2] + '" title="' + banners4[index][3] + '" target="_blank"/><img src="' + banners4[index][0] + '" border="0" id="ban_img4"  /></a>';
		else
			st = '<img src="' + banners4[index][0] + '" border="0" id="ban_img4" />';	
	if ( banner4_show > 1 ) {
		FadeOut ( banner_div, 'ban_img4', 1, st );
		if ( banner4_show <= count )		
			ScoreBanner ( banners4[index][4], banners4[index][5] );
	}
	else
		banner_div.innerHTML = st;
	//FadeIn ( document.getElementById ( 'banner1' ), 0 );
	if ( count > 1 )
		setTimeout ( function() { ChangeBanner4 ( index+1, count ) }, banners4[index][1]*1000 );
}

function MenuPos () {	
	if ( document.body.offsetHeight > document.documentElement.clientHeight )
		ht =  document.body.offsetHeight + 50;
	else {
		if ( navigator.userAgent.indexOf("MSIE") != -1 )
			ht =  document.documentElement.clientHeight + 20;
		else
			ht =  document.documentElement.clientHeight;
	}
}