function toggle_slide_main(target,exp_days){
  if ($("#"+target).is(":hidden")){
	  $("#"+target).show("slow");setCookie(target, "show", exp_days);
	  $("#"+target+'_ico').attr('src','http://img.ibtimes.com/www/site/us/images/icon_minus_main.gif');
  }else {
	  $("#"+target).slideUp();setCookie(target, "hide", exp_days);
	  $("#"+target+'_ico').attr('src','http://img.ibtimes.com/www/site/us/images/icon_plus_main.gif');
  }
}
function check_slide_main(target){
	if(getCookie(target)=="hide"){
		$("#"+target).hide();
		$("#"+target+'_ico').attr('src','http://img.ibtimes.com/www/site/us/images/icon_plus_main.gif');
	}else{
		$("#"+target).show();
		$("#"+target+'_ico').attr('src','http://img.ibtimes.com/www/site/us/images/icon_minus_main.gif');
	}
} 

/**************************************
Top Header News
**************************************/
function header_slide(photo_width,photo_limit){
	
		this.Obj;  
		this.amount;
		this.picture_space = photo_width;
		this.speed;
		this.num = 0;	
		this.moving = true;
		this.target;
		this.autos;
		this.pho_limit=photo_limit;
}		
header_slide.prototype.move = function(val){
			if(this.autos) clearTimeout(this.autos);
			if(this.moving){
				this.Obj = document.getElementById("showbx");
				if(val==(this.pho_limit-1)){ 
					this.moving = false;					
					if(this.num<this.pho_limit){					
						this.amount = (this.num+1)*this.picture_space;
						this.target = -1*this.picture_space*(this.num+1);
						this.go_right();
						this.num++;
					}else{
						this.num=0;
						this.Obj.style.left = "0px";
						this.amount = (this.num+1)*this.picture_space;
						this.target = -1*this.picture_space*(this.num+1);
						this.go_right();
						this.num++;				
					}		
				}else{		
					this.moving = false;		
					if(this.num>0){ 
						
						this.amount = (this.num-1)*this.picture_space;
						this.target = -1*this.picture_space*(this.num-1);
						this.go_left();
						this.num--;
					}else{
						this.num=this.pho_limit;
						this.Obj.style.left = -1*this.picture_space*this.num+"px";
						this.amount = (this.num-1)*this.picture_space;
						this.target = -1*this.picture_space*(this.num-1);
						this.go_left();
						this.num--;					
					}	
				}
			}	
		}
header_slide.prototype.go_left =  function (){
			this.Obj = document.getElementById("showbx");
			if(this.Obj.style.left=="") this.Obj.style.left = "-1px";
			var current_pos = parseInt(this.Obj.style.left.substring(0,this.Obj.style.left.indexOf('px')));
			this.speed = -1*parseInt((current_pos+this.amount)/3)+8;
			
			this.Obj.style.left = current_pos + this.speed + "px";
			var sss = window.setTimeout("hs.go_left()",100);
			if(current_pos>(this.target-11)){ 
				clearTimeout(sss);
				this.Obj.style.left = this.target+"px";
				this.autos = window.setTimeout("hs.automatic()",5000);
				this.moving = true;
			}			
		}	
header_slide.prototype.go_right = function(){
			this.Obj = document.getElementById("showbx");
			if(this.Obj.style.left=="") this.Obj.style.left = "-1px";
			var current_pos = parseInt(this.Obj.style.left.substring(0,this.Obj.style.left.indexOf('px')));
			this.speed = parseInt((current_pos+this.amount)/3)+8;
			this.Obj.style.left = current_pos - this.speed + "px";
			var sss = window.setTimeout("hs.go_right()",100);
			if(current_pos<(this.target+12)){ 
				clearTimeout(sss);
				this.Obj.style.left = this.target+"px";
				this.autos = window.setTimeout("hs.automatic()",5000);
				this.moving = true;
			}			
		}
header_slide.prototype.automatic= function(){
	
			if(this.moving){
				this.Obj = document.getElementById("showbx");				
				this.moving = false;			
				if(this.num==this.pho_limit){
					this.num = 0;
					this.Obj.style.left = "0px";
				}
				if(this.num<this.pho_limit){
					this.amount = (this.num+1)*this.picture_space;
					this.target = -1*this.picture_space*(this.num+1);
					this.go_right();
					this.num++;
				}	
			}		
		}


/**************************************
Markets
**************************************/

var marketdata = function(setoff){
	var offday = setoff;
	var gc_arr =new Array(Array("^DJI","$COMP","$SPX","$NYA"),Array("$FTSE","$PARI","$DAX","$SSMI"),Array("$N225","$SHANG","$HSI","$BSESN"));
	var curnum=0;
	var color;
	this.moveTab_mkt = function(total,cur,symb){
	    for(i=0;i<total;i++){
	        if(cur==i){
	            $('#gc_data'+i).addClass("current");
	        }else{
	            $('#gc_data'+i).removeClass("current");
	        }
	    }
	    this.chg_gc_row(symb);
	    curnum=cur;
	}
	this.change_graph = function(symb){
		if(symb=="^DJI"&&offday==true){
		    $('#mkgraph').attr('src','http://app.quotemedia.com/quotetools/getChart?webmasterId=97243&snap=true&chscale=1d&cp=off&chtype=AreaChart&chwid=285&chhig=147&chbdr=000000&chbg=ffffff&chbgch=ffffff&chfill=B4D4ED&chfill2=ccCEE0EE&chgrd=dddddd&chln=333333&chxyc=000000&chpccol=ff0000&chfrmon=false&chton=false&chpcon=true&symbol='+symb);
		}
		else {
		    $('#mkgraph').attr('src','http://chart.financialcontent.com/Chart?width=285&vucolor=008000&bvcolor=FFFFFF&gtcolor=004276&bgcolor=null&gbcolor=FFFFFF&Client=ibtimes&watermark=null&brcolor=999999&pvcolor=999999&ibcolor=FFFFFF&vdcolor=FF0000&wmalpha=50&volume=0&fillalpha=60&height=147&lncolor=004276&arcolor=null&txcolor=000000&itcolor=000000&grcolor=EEEEEE&type=0&shcolor=999999&shwidth=0&interval=1&ticker='+symb);
	    }
	}

	this.gc_group = function (num){
	        for(i=0;i<gc_arr.length;i++){
	            if(num==i){
	                $('#tab_mkt'+i).addClass("current");
	            }else{
	                $('#tab_mkt'+i).removeClass("current");
	            }
	        }    
	        var text='<table width="100%" border="0" cellspacing="0" cellpadding="0" id="tb_chart">';
	        var footertext=' </table>';
	        for(var j=0;j<gc_arr[num].length;j++){
	            symb=(gc_arr[num][j]);
	            k=j;
	            bcQuotes[symb].volume=bcQuotes[symb].name;
	            if(bcQuotes[symb].change>0){color="green";}else if(bcQuotes[symb].change<0){color="red";} else{color="stay";}
	            var change=this.onlynumber(bcQuotes[symb].change);
	            if(j==0)cur="class=\"current\"";else cur="";
	            text=text+"<tr id=\"gc_data"+k+"\" "+cur+" onClick=\"mkdata.moveTab_mkt('"+gc_arr[num].length+"','"+k+"','"+symb+"');\"><th width=\"105\"><a href=\"javascript:;\" onFocus=\"this.blur();\">"+ bcQuotes[symb].volume +"</a></th><th width=\"65\" class=\"gc_last\">"+ bcQuotes[symb].last +"</th><td><span class=\""+color+"_chart\">" + change + "</span> <img src=\"http://img.ibtimes.com/www/site/us/images/icon_chart_"+color+".gif\" border=\"0\" /></td><td><span class=\""+color+"_chart\">" + bcQuotes[symb].pctChg + "%</span></td></tr>";
	        }
	        $('#gc_eachdata').html(text+footertext);
	        this.chg_gc_row(gc_arr[num][0]);
	}
	this.chg_gc_row = function(symbol){    
	    var gc_hour,gc_minute,gc_ampm="AM";
	    this.change_graph(symbol);
	    if(bcQuotes[symbol].date>19800305){
	        mcg_year=parseInt(bcQuotes[symbol].date.substring(0,4))-2000;
	        mcg_month=parseInt(bcQuotes[symbol].date.substring(4,6));
	        mcg_day=bcQuotes[symbol].date.substring(6,8);
	        if(mcg_day.substring(0,1)=="0")mcg_day=bcQuotes[symbol].date.substring(7,8);
	        if(bcQuotes[symbol].time.substring(0,1)=="0")mcg_hour=bcQuotes[symbol].time.substring(1,2);
	        else mcg_hour=bcQuotes[symbol].time.substring(0,2);
	        if(mcg_hour!=0)mcg_hour=parseInt(mcg_hour);
	        if(mcg_hour>23)mcg_hour=0;
	        else if(mcg_hour>=12){gc_ampm="PM";}
	        if(mcg_hour>12){mcg_hour=mcg_hour-12;}
	        mcg_minute=bcQuotes[symbol].time.substring(2,4);
	        if(mcg_hour==0&&mcg_minute=="00")var time_text="At close "+mcg_month+"/"+mcg_day+"/"+mcg_year;
	        else var time_text=mcg_month+"/"+mcg_day+"/"+mcg_year+" "+mcg_hour+":"+mcg_minute+" "+gc_ampm+" EST";
	        $('#mcg_time').html(time_text);
	    }
	}
	this.onlynumber = function(input) {
	    var chars = ".,0123456789";
	    var new_chars="";
	    if(input){for (var inx = 0; inx < input.length; inx++) {
	           if (chars.indexOf(input.charAt(inx)) != -1){new_chars=new_chars+input.charAt(inx);}
	    }}
	    return new_chars;
	}
	this.updateticker = function(){
	    var myticker = document.navform['Ticker'].value;
	    if(myticker)setCookie('myticker',myticker,0.001);
	    if (myticker == 'Enter symbol'||myticker == '') {
	        myticker = ""    
	        document.navform['Ticker'].value = myticker;
	    }
	}
}


/**************************************
 3 Tabs in What's more in IBTimes
**************************************/
$(document).ready(function(){
  var tab = $('.tab_local');
	var current_tab = 0;
	var numberOfTabs = 3;
  tab.each(function(){

	  
	  
	  $(this).click(function() {
		  for(i=0;i<numberOfTabs;i++){
			if($('#tab_local'+i).attr('id')==$(this).attr('id')){
				$('#tab_local'+i).addClass("current");
				$('#con_local'+i).show();				
				current_tab = i;
			}else{
				$('#tab_local'+i).removeClass("current");
				$('#con_local'+i).hide();
			}
		  }
	 });
	 

  });
  
  $("#tab_arrow_left").click(function(){
				$('#tab_local'+current_tab).removeClass("current");
				$('#con_local'+current_tab).hide();
				current_tab--;
				if(current_tab < 0){
					current_tab = numberOfTabs - 1;
				}
				$('#tab_local'+current_tab).addClass("current");
				$('#con_local'+current_tab).show();				

  	});
  	
  $("#tab_arrow_right").click(function(){
				$('#tab_local'+current_tab).removeClass("current");
				$('#con_local'+current_tab).hide();
				current_tab++;
				if(current_tab >= numberOfTabs){
					current_tab = 0;
				}
				$('#tab_local'+current_tab).addClass("current");
				$('#con_local'+current_tab).show();				
  	});
  
});


/* Bottom New Box */
$(document).ready(function(){
				/* Setting from PHP 
					data key Exaplanation
					 2 digit = type
					 2 digit = category type
					 next number = id
				*/
				var maindata1 = {
										u1:{			
															name:"Auto",
															"data":{	"ctca61":"Company News",
																			"ctca62":"Used Cars",
																			"ctca63":"Reviews",
																			"ctca64":"Tips & Advice",
																			"ctca65":"Green Cars",
																			"ctca66":"New Cars",
																			"ctca83":"Industry News",
																			"ctca86":"Commentary"
																			}	,
														 "totalct":9	
														 				
									   },
										u2:{			
															name:"Life & Style",
															"data":{	"ctca71":"Fashion",
																			"ctca72":"Design",
																			"ctca73":"Luxury"
																			}	,
														 "totalct":3
														 				
									   },
										u4:{			
															name:"Travel",
															"data":{	"ctca22":"Destinations",
																			"ctca23":"Luxury Vacations",
																			"ctca25":"Cruises",
																			"ctca26":"Travel Tips",
																			"ctca68":"Adventures",
																			"ctca88":"News",
																			"ctca94":"Culture",
																			"ctca95":"Review"
																			}	,
														 "totalct":8	
														 				
									   },
										u5:{			
															name:"Health",
															"data":{	"ctmi8":"Health"
																			}	,
														 "totalct":1
														 				
									   },
										u6:{			
															name:"Real Estate",
															"data":{	"ctca51":"News",
																			"ctca52":"Buy & Sell",
																			"ctca53":"Finance & Mortgage",
																			"ctca54":"Rent & Leasing",
																			"ctca55":"Top Properties",
																			"ctca56":"Home & Garden",
																			"ctca60":"Commercial",
																			"ctca85":" Investment",
																			"ctca91":"Tips & Advice",
																			"ctca92":"News and Commentaries"
																			}	,
														 "totalct":10
														 				
									   }
									};
					var content_order		= 1;				
					var init_key 				= maindata1.u1;
					var start_section   = "u1";
					var init_section 		= "u1";
					var init_subsection = "ctca61";
					var init_menu_count = 6;
					var init_menu_cur   = 1;
					/* end to setting from php */
					
					/************************************** 
					initaialize sections and mnu setting
					setting Section 
					**************************************/
					var str 	= "";
					var str1 	= "";
					var i			= 0;
					var addopt= "";
					
					for (var key in maindata1){
						str += "<li id=\"dp_"+content_order+"_"+key+"\">"+maindata1[key].name+"</li> \r\n";
						i++;
					}
					$("#dropmenu_"+content_order+" ul").html(str);
					
					/* setting Menu */
					i					= 1;
					for(var k in init_key.data){
						if(i==1)	addopt = 'class="selected"';
						else			addopt = '';
 
						
						str1 += "<li "+addopt+" id=\"sd_"+content_order+"_"+k+"\">"+init_key.data[k]+"</li> ";
						i++;
					}
					$("#wrap_news"+content_order+" .section_list").append(str1);
					$("#select_btn_"+content_order+" .number").html(init_menu_cur+" of " + maindata1[init_section].totalct);
					//forajax(init_subsection);	
					/********************************************
					Initialization is finished.
					Next Event Function
					********************************************/
					
					//Add Event for Click
					$("ul#sb_topic_"+content_order+"  li").click(function(){
							var strid 				= $(this).attr("id");
							set_click(strid);
					});
 
					
					$("#dropmenu_"+content_order+" ul li").click(function(){
							var strid 				= $(this).attr("id");
							var id_info_array = strid.split('_');
							var mainid				= id_info_array[2];
							var curid					= id_info_array[1];
							i									= 1;
							var str1					= "";
							var addopt        = "";
							for(var k in maindata1[mainid].data){
								if(i==1){	addopt = 'class="selected"'; init_subsection = k}
								else			addopt = '';
								
								
								str1 += "<li "+addopt+" id=\"sd_"+content_order+"_"+k+"\">"+maindata1[mainid].data[k]+"</li> ";
								i++;
								
							}
							$(this).parent().parent().slideUp();
							$("#wrap_news"+curid+" .section_list li").remove();
							$("#wrap_news"+curid+" .section_list").append(str1);
							$("#select_btn_"+curid+" .number").html("1 of " + maindata1[mainid].totalct);
 
							//Add Event for Click
							$("ul#sb_topic_"+content_order+"  li").click(function(){
									var strid 				= $(this).attr("id");
									set_click(strid);
							});
							// setting configure
							init_menu_count = maindata1[mainid].totalct;
							init_menu_cur   = 1;
							init_section 		= mainid;
							$(".dropdown #select_section_"+content_order).html(maindata1[init_section].name);
							
							/* Add for Ajax Part */		
							forajax(init_subsection);				
 
						});
					/* Common Function */
					function set_click(strid){ 							
							$(".section_list li#sd_"+content_order+"_"+init_subsection).attr("class","noselected");
							$(".dropdown #select_section_"+content_order).html(maindata1[init_section].name);
							var id_info_array = strid.split('_');
							var subid				= id_info_array[2];
							var curid					= id_info_array[1];
 
							
							var i=1;
							for(var k in maindata1[init_section].data){
								  if(k == subid){
								  	init_menu_cur = i;
								  	break;
								  }
									i++;
							}
                            
							init_subsection = subid;
							$("#select_btn_"+content_order+" .number").html(init_menu_cur+" of " + init_menu_count);
							$(".section_list li#sd_"+content_order+"_"+init_subsection).attr("class","selected");
														
							/* Ajax */
							forajax(init_subsection);				
					}
					
					
					function forajax(strid){
						
						var maintype 	= strid.substring(0,2);
						var maincat  	= strid.substring(2,4);
						var maincatid	= strid.substring(4);
						var URLstr   	= "/mainpage/ajax/ajax_section_box.php";
						URLstr				+="?type="+maintype;
						
						if(maincat == 'ca')					URLstr				+="&category_id="+maincatid;
						else 												URLstr				+="&maincat_id="+maincatid;
						URLstr				+= "&limit=6";
						
                        
						loadpage('mbox_'+content_order,URLstr,'http://img.ibtimes.com/www/site/us/images/ajax_load.gif',70);
					}
					
					$(".dropdown").click(function(){
							
							$(this).find(" #select_section_"+content_order).html("Select Section");
							if($(this).parent().find(".dropbox").css('display') == 'none')
								$(this).parent().find(".dropbox").slideDown();
							else    
								$(this).parent().find(".dropbox").slideUp();
					});
 
 
	
					$("#select_btn_"+content_order+" .bt_go .btnprev").click(function(){
						 	var checup = false ;
						 	var store  = "";
						 	var prev_subkey = "";
						 	var prev_mainkey = "";
							$(".section_list li#sd_"+content_order+"_"+init_subsection).attr("class","noselected");
							for(var k in maindata1[init_section].data ){
								if(k == init_subsection){
									prev_subkey = store;
									break;
								}
								store = k;
							}
							
							if(prev_subkey){
								prev_mainkey = init_section;
								init_menu_cur--;
								$("#select_btn_"+content_order+" .number").html(init_menu_cur+" of " + maindata1[init_section].totalct);
							}else{
								store = "";
								for(var j in maindata1 ){
									if(init_section == j && store){
										prev_mainkey = store;
										break;
									}
									store = j;
								}
								if(!prev_mainkey)prev_mainkey = store;
								for(var l in maindata1[prev_mainkey].data){
									prev_subkey	 = l;
								}
								
								str1 = "";								
								for(var m in maindata1[prev_mainkey].data){
									str1 += "<li id=\"sd_"+content_order+"_"+m+"\">"+maindata1[prev_mainkey].data[m]+"</li> \r\n";
								}
								$("#wrap_news"+content_order+" .section_list").html(str1);
								//Add Event for Click
								$("ul#sb_topic_"+content_order+"  li").click(function(){
										var strid 				= $(this).attr("id");
										set_click(strid);
								});
 
								init_menu_cur		= maindata1[prev_mainkey].totalct;								
								init_menu_count = maindata1[prev_mainkey].totalct;
								$("#select_btn_"+content_order+" .number").html(init_menu_cur+" of " + init_menu_count);
										
							}
 
							
							
							
							init_subsection = prev_subkey;
							init_section 		= prev_mainkey;
							$(".dropdown #select_section_"+content_order).html(maindata1[init_section].name);
							$(".section_list li#sd_"+content_order+"_"+prev_subkey).attr("class","selected");
							/* Add AJAX for section */
							forajax(init_subsection);				
 
						});
					$("#select_btn_"+content_order+" .bt_go .btnnext").click(function(){
						 	var checkup = false ;
						 	var next_subkey = "";
						 	var next_mainkey = "";
						 	$(".section_list li#sd_"+content_order+"_"+init_subsection).attr("class","noselected");
						 	
						 	
							for(var k in maindata1[init_section].data ){
								if(checkup == true){
									next_subkey = k;
									break;
								}
								if(k == init_subsection)checkup = true;
							}
							/* Common Part */
							if(next_subkey){
								next_mainkey = init_section;
								init_menu_cur++;
								$("#select_btn_"+content_order+" .number").html(init_menu_cur+" of " + maindata1[init_section].totalct);
							
							/* Speicial Part */
							}else{
								
								checkup = false;
								for(var j in maindata1 ){
									if(checkup == true){
										next_mainkey = j;
										break;
									}
									if(j == init_section)checkup = true;
								}
								if(!next_mainkey){
									next_mainkey = start_section;
								}
								for(var l in maindata1[next_mainkey].data){
									next_subkey	 = l;
									break;
								}
 
								str1 = "";
								for(var m in maindata1[next_mainkey].data){
									str1 += "<li "+addopt+" id=\"sd_"+content_order+"_"+m+"\">"+maindata1[next_mainkey].data[m]+"</li> \r\n";
								}
								$("#wrap_news"+content_order+" .section_list").html(str1);
								init_menu_cur		= 1;
								init_menu_count = maindata1[next_mainkey].totalct;
								$("#select_btn_"+content_order+" .number").html(init_menu_cur+" of " + init_menu_count);
 
							}
							
							init_subsection = next_subkey;
							init_section 		= next_mainkey;
							$(".dropdown #select_section_"+content_order).html(maindata1[init_section].name);
							$(".section_list li#sd_"+content_order+"_"+next_subkey).attr("class","selected");
							/* Add AJAX for section */
								//Add Event for Click
								$("ul#sb_topic_"+content_order+"  li").click(function(){
										var strid 				= $(this).attr("id");
										set_click(strid);
								});
 
							forajax(init_subsection);				
						});
	});


$(document).ready(function(){
                /* Setting from PHP 
                    data key Exaplanation
                     2 digit = type
                     2 digit = category type
                     next number = id
                */
                var maindata1 = {
                                        u1:{            
                                                            name:"Finance",
                                                            "data":{ 
                                                                    "ctmi1":"Forexperts",
                                                                    "ctmi7":"Small Cap News Movers",
                                                                    "ctmi17":"Finance Brief"
                                                                            }    ,
                                                         "totalct":3   
                                                                         
                                       },
                                        u2:{            
                                                            name:"Technology",
                                                            "data":{    
                                                                    "ctmi13":"Teknowledge",
                                                                    "ctmi19":"Gadgetek",
                                                                    "ctmi18":"iPhone Booth"
                                                                            }    ,
                                                         "totalct":3  
                                                                         
                                       },
                                        u3:{            
                                                            name:"Business",
                                                            "data":{ 
																	"ctmi16":"Leadership Journal",
																	"ctmi20":"Media & Marketing",
																	"ctmi26":"Joblessness",
																	"ctmi27":"Career Wise"
                                                                            }    ,
                                                         "totalct":4   
                                                                         
                                       },
                                        u4:{            
                                                            name:"Life & Style",
                                                            "data":{ 
																	"ctmi25":"Real Estator",
																	"ctmi28":"Autopia",
																	"ctmi30":"Wellbeing"
                                                                            }    ,
                                                         "totalct":3   
                                                                         
                                       }
                                    };
                    var content_order        = 2;                
                    var init_key                 = maindata1.u1;
                    var start_section   = "u1";
                    var init_section         = "u1";
                    var init_subsection = "ctmi1";
                    var init_menu_count = 6;
                    var init_menu_cur   = 1;
                    /* end to setting from php */
                    
                    /************************************** 
                    initaialize sections and mnu setting
                    setting Section 
                    **************************************/
                    var str     = "";
                    var str1     = "";
                    var i            = 0;
                    var addopt= "";
                    
                    for (var key in maindata1){
                        str += "<li id=\"dp_"+content_order+"_"+key+"\">"+maindata1[key].name+"</li> \r\n";
                        i++;
                    }
                    $("#dropmenu_"+content_order+" ul").html(str);
                    
                    /* setting Menu */
                    i                    = 1;
                    for(var k in init_key.data){
                        if(i==1)    addopt = 'class="selected"';
                        else            addopt = '';
 
                        
                        str1 += "<li "+addopt+" id=\"sd_"+content_order+"_"+k+"\">"+init_key.data[k]+"</li> ";
                        i++;
                    }
                    $("#wrap_news"+content_order+" .section_list").append(str1);
                    $("#select_btn_"+content_order+" .number").html(init_menu_cur+" of " + maindata1[init_section].totalct);
                    forajax(init_subsection);    
                    /********************************************
                    Initialization is finished.
                    Next Event Function
                    ********************************************/
                    
                    //Add Event for Click
                    $("ul#sb_topic_"+content_order+"  li").click(function(){
                            var strid                 = $(this).attr("id");
                            set_click(strid);
                    });
 
                    
                    $("#dropmenu_"+content_order+" ul li").click(function(){
                            var strid                 = $(this).attr("id");
                            var id_info_array = strid.split('_');
                            var mainid                = id_info_array[2];
                            var curid                    = id_info_array[1];
                            i                                    = 1;
                            var str1                    = "";
                            var addopt        = "";
                            for(var k in maindata1[mainid].data){
                                if(i==1){    addopt = 'class="selected"'; init_subsection = k}
                                else            addopt = '';
                                
                                
                                str1 += "<li "+addopt+" id=\"sd_"+content_order+"_"+k+"\">"+maindata1[mainid].data[k]+"</li> ";
                                i++;
                                
                            }
                            $(this).parent().parent().slideUp();
                            $("#wrap_news"+curid+" .section_list li").remove();
                            $("#wrap_news"+curid+" .section_list").append(str1);
                            $("#select_btn_"+curid+" .number").html("1 of " + maindata1[mainid].totalct);
 
                            //Add Event for Click
                            $("ul#sb_topic_"+content_order+"  li").click(function(){
                                    var strid                 = $(this).attr("id");
                                    set_click(strid);
                            });
                            // setting configure
                            init_menu_count = maindata1[mainid].totalct;
                            init_menu_cur   = 1;
                            init_section         = mainid;
                            $(".dropdown #select_section_"+content_order).html(maindata1[init_section].name);
                            
                            /* Add for Ajax Part */        
                            forajax(init_subsection);                
 
                        });
                    /* Common Function */
                    function set_click(strid){                             
                            $(".section_list li#sd_"+content_order+"_"+init_subsection).attr("class","noselected");
                            $(".dropdown #select_section_"+content_order).html(maindata1[init_section].name);
                            var id_info_array = strid.split('_');
                            var subid                = id_info_array[2];
                            var curid                    = id_info_array[1];
 
                            
                            var i=1;
                            for(var k in maindata1[init_section].data){
                                  if(k == subid){
                                      init_menu_cur = i;
                                      break;
                                  }
                                    i++;
                            }
                            
                            init_subsection = subid;
                            $("#select_btn_"+content_order+" .number").html(init_menu_cur+" of " + init_menu_count);
                            $(".section_list li#sd_"+content_order+"_"+init_subsection).attr("class","selected");
                                                        
                            /* Ajax */
                            forajax(init_subsection);                
                    }
                    
                    
                    function forajax(strid){
                        
                        var maintype     = strid.substring(0,2);
                        var maincat      = strid.substring(2,4);
                        var maincatid    = strid.substring(4);
                        var URLstr       = "/mainpage/ajax/ajax_blog_box.php";
                        URLstr                +="?type="+maintype;
                        
                        if(maincat == 'ca')                    URLstr                +="&category_id="+maincatid;
                        else                                                 URLstr                +="&maincat_id="+maincatid;
                        URLstr                += "&limit=7";
                        
                        
                        loadpage('mbox_'+content_order,URLstr,'http://img.ibtimes.com/www/site/us/images/ajax_load.gif',70);
                    }
                    /*
                    $(".dropdown").click(function(){
                            
                            $(this).find(" #select_section_"+content_order).html("Select Section");
                            if($(this).parent().find(".dropbox").css('display') == 'none')
                                $(this).parent().find(".dropbox").slideDown();
                            else
                                $(this).parent().find(".dropbox").slideUp();
                    });
                     */
 
    
                    $("#select_btn_"+content_order+" .bt_go .btnprev").click(function(){
                             var checup = false ;
                             var store  = "";
                             var prev_subkey = "";
                             var prev_mainkey = "";
                            $(".section_list li#sd_"+content_order+"_"+init_subsection).attr("class","noselected");
                            for(var k in maindata1[init_section].data ){
                                if(k == init_subsection){
                                    prev_subkey = store;
                                    break;
                                }
                                store = k;
                            }
                            
                            if(prev_subkey){
                                prev_mainkey = init_section;
                                init_menu_cur--;
                                $("#select_btn_"+content_order+" .number").html(init_menu_cur+" of " + maindata1[init_section].totalct);
                            }else{
                                store = "";
                                for(var j in maindata1 ){
                                    if(init_section == j && store){
                                        prev_mainkey = store;
                                        break;
                                    }
                                    store = j;
                                }
                                if(!prev_mainkey)prev_mainkey = store;
                                for(var l in maindata1[prev_mainkey].data){
                                    prev_subkey     = l;
                                }
                                
                                str1 = "";                                
                                for(var m in maindata1[prev_mainkey].data){
                                    str1 += "<li id=\"sd_"+content_order+"_"+m+"\">"+maindata1[prev_mainkey].data[m]+"</li> \r\n";
                                }
                                $("#wrap_news"+content_order+" .section_list").html(str1);
                                //Add Event for Click
                                $("ul#sb_topic_"+content_order+"  li").click(function(){
                                        var strid                 = $(this).attr("id");
                                        set_click(strid);
                                });
 
                                init_menu_cur        = maindata1[prev_mainkey].totalct;                                
                                init_menu_count = maindata1[prev_mainkey].totalct;
                                $("#select_btn_"+content_order+" .number").html(init_menu_cur+" of " + init_menu_count);
                                        
                            }
 
                            
                            
                            
                            init_subsection = prev_subkey;
                            init_section         = prev_mainkey;
                            $(".dropdown #select_section_"+content_order).html(maindata1[init_section].name);
                            $(".section_list li#sd_"+content_order+"_"+prev_subkey).attr("class","selected");
                            /* Add AJAX for section */
                            forajax(init_subsection);                
 
                        });
                    $("#select_btn_"+content_order+" .bt_go .btnnext").click(function(){
                             var checkup = false ;
                             var next_subkey = "";
                             var next_mainkey = "";
                             $(".section_list li#sd_"+content_order+"_"+init_subsection).attr("class","noselected");
                             
                             
                            for(var k in maindata1[init_section].data ){
                                if(checkup == true){
                                    next_subkey = k;
                                    break;
                                }
                                if(k == init_subsection)checkup = true;
                            }
                            /* Common Part */
                            if(next_subkey){
                                next_mainkey = init_section;
                                init_menu_cur++;
                                $("#select_btn_"+content_order+" .number").html(init_menu_cur+" of " + maindata1[init_section].totalct);
                            
                            /* Speicial Part */
                            }else{
                                
                                checkup = false;
                                for(var j in maindata1 ){
                                    if(checkup == true){
                                        next_mainkey = j;
                                        break;
                                    }
                                    if(j == init_section)checkup = true;
                                }
                                if(!next_mainkey){
                                    next_mainkey = start_section;
                                }
                                for(var l in maindata1[next_mainkey].data){
                                    next_subkey     = l;
                                    break;
                                }
 
                                str1 = "";
                                for(var m in maindata1[next_mainkey].data){
                                    str1 += "<li "+addopt+" id=\"sd_"+content_order+"_"+m+"\">"+maindata1[next_mainkey].data[m]+"</li> \r\n";
                                }
                                $("#wrap_news"+content_order+" .section_list").html(str1);
                                init_menu_cur        = 1;
                                init_menu_count = maindata1[next_mainkey].totalct;
                                $("#select_btn_"+content_order+" .number").html(init_menu_cur+" of " + init_menu_count);
 
                            }
                            
                            init_subsection = next_subkey;
                            init_section         = next_mainkey;
                            $(".dropdown #select_section_"+content_order).html(maindata1[init_section].name);
                            $(".section_list li#sd_"+content_order+"_"+next_subkey).attr("class","selected");
                            /* Add AJAX for section */
                                //Add Event for Click
                                $("ul#sb_topic_"+content_order+"  li").click(function(){
                                        var strid                 = $(this).attr("id");
                                        set_click(strid);
                                });
 
                            forajax(init_subsection);                
                        });
    });	

