ad_url = new Array();ad_url1 = new Array();ad_click_url = new Array();ad_content = new Array();ad_width = new Array();ad_height = new Array();ad_mediatype = new Array();ad_opentype = new Array();ad_showtype = new Array();ad_brandid = new Array();ad_catesubid = new Array();ad_modelid = new Array();ad_brandid_skip = new Array();ad_catesubid_skip = new Array();ad_modelid_skip = new Array();function show_special_ad(curr_ad_info){ 

	var tmp_ad_url = curr_ad_info[0];

	var tmp_ad_click_url = curr_ad_info[1];

	var tmp_ad_content = curr_ad_info[2];

	var tmp_ad_width = curr_ad_info[3];

	var tmp_ad_height = curr_ad_info[4];

	var tmp_ad_mediatype = curr_ad_info[5];

	var tmp_ad_opentype = curr_ad_info[6];

	var tmp_ad_url1 = curr_ad_info[7];

	var tmp_ad_showtype = curr_ad_info[8]; 	 

	var pos_id =  curr_ad_info[9]; 	 

	switch(tmp_ad_showtype){

		case "0":	 			

			if(tmp_ad_mediatype == "jpg" || tmp_ad_mediatype == "gif" || tmp_ad_mediatype == "png"){

				$("#ad_pos_"+pos_id).html("<a href = \""+ tmp_ad_click_url +"\" target = \""+ tmp_ad_opentype +"\"><img src = \""+ tmp_ad_url +"\" width = \""+ tmp_ad_width +"\" height = \""+ tmp_ad_height +"\" border = \"0\"></a>");		

			}else if(tmp_ad_mediatype == "swf"){  

				$("#ad_pos_"+pos_id).html("<embed quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" scale=\"exactfit\" src=\""+ tmp_ad_url + "\" height= \""+tmp_ad_height+"\" width= \""+tmp_ad_width+"\" wmode=\"opaque\"></embed>"); 

			}else{

				document.write("<a href = '"+ tmp_ad_click_url +"' target = \"+ tmp_ad_opentype +\">"+ tmp_ad_content +"</a>");

			}

			break;

		case "1":

			if(tmp_ad_mediatype == "jpg" || tmp_ad_mediatype == "gif" || tmp_ad_mediatype == "png"){

				$("#ad_pos_"+pos_id).html("<a href = \""+ tmp_ad_click_url +"\" target = \""+ tmp_ad_opentype +"\"><img src = \""+ tmp_ad_url +"\" width = \""+ tmp_ad_width +"\" height = \""+ tmp_ad_height +"\" border = \"0\"></a><a href = \""+ tmp_ad_click_url +"\" target = \""+ tmp_ad_opentype +"\"><img src = \""+ tmp_ad_url1 +"\" width = \""+ tmp_ad_width +"\" height = \""+ tmp_ad_height +"\" border = \"0\"></a>"); 

			}else if(tmp_ad_mediatype == "swf"){

				$("#ad_pos_"+pos_id).css("width",tmp_ad_width+"px").css("margin-left","auto").css("margin-right","auto");

				$("#ad_pos_"+pos_id).html("<div style='display:none'><embed quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" scale=\"exactfit\" src=\""+ tmp_ad_url + "\" height= \"50\" width= \""+tmp_ad_width+"\" wmode=\"opaque\"></embed></div>");

				$("#ad_pos_"+pos_id).append("<div><embed quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" scale=\"exactfit\" src=\""+ tmp_ad_url1 + "\" height= \""+tmp_ad_height+"\" width= \""+tmp_ad_width+"\" wmode=\"opaque\"></embed></div>");

				setTimeout( "$('#ad_pos_"+pos_id+" div').eq(1).hide();$('#ad_pos_"+pos_id+" div').eq(0).show();", "5000");

			}else{

				document.write("<a href = '"+ tmp_ad_click_url +"' target = \"+ tmp_ad_opentype +\">"+ tmp_ad_content +"</a>");

			}

			break;

		case "3":

			if(tmp_ad_mediatype == "jpg" || tmp_ad_mediatype == "gif" || tmp_ad_mediatype == "png"){

				$("#ad_pos_"+pos_id).html("<a href = \""+ tmp_ad_click_url +"\" target = \""+ tmp_ad_opentype +"\"><img src = \""+ tmp_ad_url + "\" width = \""+ tmp_ad_width +"\" height = \""+ tmp_ad_height +"\" border = \"0\"></a>");

				setTimeout( "$('#ad_pos_"+pos_id+"').html(' ').hide();", "5000");

			}else if(tmp_ad_mediatype == "swf"){

				$("#ad_pos_"+pos_id).html("<div><embed quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" scale=\"exactfit\" src=\""+ tmp_ad_url + "\" height= \""+tmp_ad_height+"\" width= \""+tmp_ad_width+"\" wmode=\"opaque\"></embed></div>");

				if(tmp_ad_url1 != ''){

				$("#ad_pos_"+pos_id).append("<div style=\"display:none\"><embed quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" scale=\"exactfit\" src=\""+ tmp_ad_url1 +"\" height= \"90\" width= \"980\" wmode=\"opaque\"></embed></div>");

				}

				setTimeout( "$('#ad_pos_"+pos_id+" div').eq(0).hide();$('#ad_pos_"+pos_id+" div').eq(1).show();", "5000");

			}else{

				$("#ad_pos_"+pos_id).html("<a href = '"+ tmp_ad_click_url +"' target = \"+ tmp_ad_opentype +\">"+ tmp_ad_content +"</a>");

				setTimeout( "$('#ad_pos_"+pos_id+"').html(' ').hide();", "5000");

			}

			break;


		default: 

			break; 

	} 

}

function get_curr_ads(pos_id,ad_brandids,ad_catesubids,ad_modelids,ad_brandid_skips,ad_catesubid_skips,ad_modelid_skips,

	ad_urls,ad_urls1,ad_click_urls,ad_contents,ad_widths,ad_heights,ad_mediatypes,ad_opentypes,ad_showtypes,default_ad_info,

	curr_page,curr_brandid,curr_catesubid,curr_modelid){ 		

	var ads_len_tmp = ad_mediatypes.length ;

	var ok_ads_len = 0;

	var ok_ads = new Array();  

	if(curr_page == "COMMON_PAGE"){		

		for(i = 0;i<ads_len_tmp;i++){  			

			var ok_tmp_ad = new Array();

			ok_tmp_ad =	get_ok_common_ad(pos_id,ad_brandids[i],ad_catesubids[i],ad_modelids[i],ad_brandid_skips[i],ad_catesubid_skips[i],ad_modelid_skips[i],		ad_urls[i],ad_urls1[i],ad_click_urls[i],ad_contents[i],ad_widths[i],ad_heights[i],ad_mediatypes[i],ad_opentypes[i],ad_showtypes[i],curr_brandid,curr_catesubid,curr_modelid);	

			if(ok_tmp_ad.length > 0){				

				ok_ads.push(ok_tmp_ad);

			}

		} 		

		ok_ads_len = ok_ads.length; 		

		if(ok_ads_len>0){

			var ads_tmp_ind  = Math.floor(Math.random()*ok_ads_len);

			var tmp_curr_ad = ok_ads[ads_tmp_ind];				

			show_special_ad(tmp_curr_ad);

			return;

		}else{	 			 

			if(default_ad_info[0].length > 0){						

				show_special_ad(default_ad_info);

				return;

			}			

		}  

	} 

}  

function get_ok_common_ad(pos_id,tmp_ad_brandid,tmp_ad_catesubid,tmp_ad_modelid,tmp_ad_brandid_skip,tmp_ad_catesubid_skip,tmp_ad_modelid_skip,

	tmp_ad_url,tmp_ad_url1,tmp_ad_click_url,tmp_ad_content,tmp_ad_width,tmp_ad_height,tmp_ad_mediatype,tmp_ad_opentype,tmp_ad_showtype,

	curr_brandid,curr_catesubid,curr_modelid){	

	var ok_ret = new Array();  

	ok_ret.push(tmp_ad_url);

	ok_ret.push(tmp_ad_click_url);

	ok_ret.push(tmp_ad_content);

	ok_ret.push(tmp_ad_width);

	ok_ret.push(tmp_ad_height);

	ok_ret.push(tmp_ad_mediatype);

	ok_ret.push(tmp_ad_opentype);

	ok_ret.push(tmp_ad_url1);

	ok_ret.push(tmp_ad_showtype);	

	ok_ret.push(pos_id);	

	return ok_ret; 

} 

function show_ad(pos_id,curr_page,curr_brandid,curr_catesubid,curr_modelid){ 

	document.write("<div id = 'ad_pos_" + pos_id + "' ></div>");

	$.getScript("http://media.carimg.com/js/"+ pos_id +".js",

		function(){

			eval("ad_brandid = ad_brandid_" + pos_id );

			eval("ad_catesubid = ad_catesubid_" + pos_id );

			eval("ad_modelid = ad_modelid_" + pos_id );

			eval("ad_brandid_skip = ad_brandid_skip_" + pos_id );

			eval("ad_catesubid_skip = ad_catesubid_skip_" + pos_id );

			eval("ad_modelid_skip = ad_modelid_skip_" + pos_id );

			eval("ad_url = ad_url_" + pos_id );

			eval("ad_url1 = ad_url1_" + pos_id );

			eval("ad_click_url = ad_click_url_" + pos_id );

			eval("ad_content = ad_content_" + pos_id );

			eval("ad_width = ad_width_" + pos_id );

			eval("ad_height = ad_height_" + pos_id );

			eval("ad_mediatype = ad_mediatype_" + pos_id );

			eval("ad_opentype = ad_opentype_" + pos_id );

			eval("ad_showtype = ad_showtype_" + pos_id );

			eval("default_ad_info = default_ad_info_" + pos_id ); 

			get_curr_ads(pos_id,ad_brandid,ad_catesubid,ad_modelid,ad_brandid_skip,ad_catesubid_skip,ad_modelid_skip,ad_url,ad_url1,ad_click_url,ad_content,ad_width,ad_height,ad_mediatype,ad_opentype,ad_showtype,default_ad_info,curr_page,curr_brandid,curr_catesubid,curr_modelid);

			if(ad_showtype == '1' && ad_mediatype == 'swf'){

				slid_ad_flash_toggle("ad_pos_"+pos_id , ad_width);

			}

		}

	); 	

}



function slid_ad_flash_toggle(e_id,w){

	$("#"+e_id).ready(function(){

		$("#"+e_id+" div").css('width',w);

		$("#"+e_id+" div").eq(0).mouseover(function(){

			$("#"+e_id+" div").eq(0).hide();

			$("#"+e_id+" div").eq(1).show();

		});

		$("#"+e_id+" div").eq(1).mouseout(function(){

			$("#"+e_id+" div").eq(1).hide();

			$("#"+e_id+" div").eq(0).show();

		});

	});

}
