// JavaScript Document
if(!window.JA) 
var JA = new Object;


JA.pageInit = {
	initMethod: function(){
		
		if(window.addEventListener){
			window.addEventListener('load',this.initFunctions,false);
		}
		else if(window.attachEvent){
			window.attachEvent('onload',this.initFunctions);
		}
		
	},
	initFunctions: function(){
		try {
			JA.themeTab.callCookie();
			JA.imgSlider.defaultBor();
			JA.imgSlider.playSlide();
			JA.imgSlider.stopSlide();
		//	sfHover('life-red','url(http://fashion.21cn.com/she2009/index/image/life-bg_2.gif)');
		//	sfHover('fashion-blue','url(http://fashion.21cn.com/she2009/index/image/fashion-bg_2.gif)');
			//addHideLinks();
		//	changeOption();

			//sfHover1();
			//JA.imgSlider.subPlay();
		}
		catch(e){}
	}
};

//change tab styls
JA.themeTab = {	
	tabs: function(tabID){
		document.getElementById(tabID).style.display = 'block';
		var hpTabs = ['fashion','life'];
		var head = document.getElementById('she-logo-red');
			
		for(var i in hpTabs){
			if(tabID != hpTabs[i]){
				document.getElementById(hpTabs[i]).style.display = 'none';
			}
			else {
				switch(hpTabs[i]){
					case 'fashion':
						head.style.backgroundImage = this.background[0];
					break;
					case 'life':
						head.style.backgroundImage = this.background[1];
					break;
				}
			}
			this.createCookie('sheCookie',tabID,365);
			she = this.readCookie('sheCookie');
		}
	},
		
	background: ['url("http://fashion.21cn.com/she2009/index/image/logo-red.gif")', 'url("http://fashion.21cn.com/she2009/index/image/logo-blue.gif")'],
		
	callCookie: function(){
		she = this.readCookie('sheCookie');
		if(she){
    		if (typeof this.tabs == "function" || !this.tabs) {
            	this.tabs(she);
			}
		}
	},
		
	readCookie: function(name){
		var nameEQ = name + "=";
  		var ca = document.cookie.split(';');
  		for(var i=0;i < ca.length;i++) {
    		var c = ca[i];
    		while (c.charAt(0)==' ') c = c.substring(1,c.length);
    			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  		}
  		return null;
	},
		
	createCookie: function(name,value,days){
		if (days) {
    		var date = new Date();
    		date.setTime(date.getTime()+(days*24*60*60*1000));
    		var expires = "; expires="+date.toGMTString();
  		}
  		else {
	  		expires = '';
  		}
  		document.cookie = name+"="+value+expires+"; path=/;";
	}
};

//tabs

JA.tabs = {
	readyTab: function(mod,cursor,n){
		for(i=1; i<=n; i++){
		var nav=document.getElementById(mod+'_'+i);
		var cont=document.getElementById(mod+"_"+"con"+i);
		nav.style.cursor = 'pointer';
			nav.className=(i==cursor)? 'on' : '';
			try {
				if(mod == 'tab2') nav.className=(i==cursor)? 'on on1' : '';	
				if(mod == 'tab4') nav.className=(i==cursor)? 'on on2' : '';
				if(mod == 'tab5') nav.className=(i==cursor)? 'on on3' : '';
			}
			catch(e){}

		cont.style.display=(i==cursor)? 'block' : 'none';
		}
	}
};

//image sliders

JA.imgSlider = {
	
	num: 1,
	
	_timeOut: 6000,

	defaultBor: function(){
		$('li#click1').addClass('init');
		$('p.title:first').addClass('init');

	},
	
	startSlider: function(value){
		for(var i=1; i<=4; i++){
			
			if(i == value){
				document.getElementById('content'+i).style.display = 'block';
				document.getElementById('title' +i).style.display = 'block';
				switch(i){
				case 1:
					document.getElementById('click'+i).className = 'red-bor';
					document.getElementById('title'+i).className = 'red-bg';
				break;
				case 2:
					document.getElementById('click'+i).className = 'green-bor';
					document.getElementById('title'+i).className = 'green-bg';
				break;
				case 3:
					document.getElementById('click'+i).className = 'blue-bor';
					document.getElementById('title'+i).className = 'blue-bg';
				break;
				case 4:
					document.getElementById('click'+i).className = 'purple-bor';
					document.getElementById('title'+i).className = 'purple-bg';
				break;
				}
			}
			else {
				document.getElementById('content'+i).style.display = 'none';
				document.getElementById('title'+i).style.display = 'none';
				document.getElementById('click'+i).className = '';
			}
		}
	},
	
	stopSlide: function(){
		$('div.focus').hover(function(){
	  		clearInterval(set);						   
		},function(){
	  		JA.imgSlider.playSlide();					  
		});
	},
	
	playSlide: function(){
		set = setInterval(function(){
			JA.imgSlider.autoPlay(4);},this._timeOut); 
	},
	
	autoPlay: function(s){
		this.num = this.num +1;
		if(this.num > s){ this.num = 1;}
		$('#click' + this.num).trigger('mouseover');

	}


};

sfHover = function(theClass,bgName) {
  var isIE = (navigator.appName == 'Microsoft Internet Explorer');
  var version = navigator.appVersion.indexOf('MSIE 6.0');
 // alert(version == -1)
  if(isIE && version!= -1){
    var sfEls = document.getElementsByTagName('li');
    for(var i=0; i<sfEls.length; i++){
	  var sfObj = sfEls[i];
	  if(sfObj.className == theClass){
		sfObj.onmouseover = function(){
		  this.style.backgroundImage = bgName ;
		}
		sfObj.onmouseout = function(){
		  this.style.backgroundImage = '';
		}
	  }  
    }
  }
}


//addHideLinks Function
addHideLinks = function(){
var obj = document.getElementsByTagName('div');
for(var i=0; i<obj.length; i++){
  var objs = obj[i];
  var indexOf1 = objs.className.indexOf('class-bar');
  
  if(indexOf1 != -1 || objs.className == 'image-promo'){
	  var lnk = document.createElement('a');
	  lnk.style.textDecoration = 'none';
	  lnk.style.display = 'block';
	  lnk.target = '_blank';
	  
	  if(indexOf1 != -1){
		  lnk.style.width = 263 +'px';
		  lnk.style.height = 58 +'px';
	  }
	  else if(objs.className == 'image-promo'){
		  lnk.style.position = 'absolute';
		  lnk.style.width = 28 +'px';
		  lnk.style.height = 116 +'px';
		  lnk.style.top = 15 +'px';
		  lnk.style.left = 22 +'px';
	  } 
		  
	  switch(objs.className){
		  case 'class-bar fashion-bar':
		  lnk.setAttribute('href','http://she.21cn.com/fashion/index.shtml');
		  break;
		  
		  case 'class-bar beauty-bar':
		  lnk.setAttribute('href','http://she.21cn.com/beauty/index.shtml');
		  break;
		  
		  case 'class-bar love-bar':
		  lnk.setAttribute('href','http://she.21cn.com/emotions/index.shtml');
		  break;
		  
		  case 'class-bar care-bar':
		  lnk.setAttribute('href','http://she.21cn.com/care/index.shtml');
		  break;
		  
		  case 'image-promo':
		  lnk.setAttribute('href','http://she.21cn.com/style/oomph/list1.shtml');
		  break;
		  
		  default:
	  }
	  
	  var childs = document.createElement('em')
	  childs.style.visibility = 'hidden';
	  var childsText = document.createTextNode('click here');
	  childs.appendChild(childsText);
	  lnk.appendChild(childs);
	  objs.appendChild(lnk);	
  }
  
}
}

//drop options
function changeOption(){
	sele = document.getElementById('changeOption');
	sele.onchange = onChanges;
}

function onChanges() {
	if (sele.options[sele.selectedIndex].value != -1) {
		window.open(sele.options[sele.selectedIndex].value);
	}
	return false;
}

JA.pageInit.initMethod();
