//var _lastLink='';
var _Theme;
var _SubTheme;
var myimages=new Array()

_Theme = getSiteTheme();
_SubTheme = getSiteSubTheme()
appendThemeJavaScript(_Theme);
function navLnk(url){
	window.location=url;
}
function rollOverNavLnk(baseObj, which){
	var _which = '';
	switch (which)
	{
		case 0:
			_which = 'Top'
			break;
		case 1:
			_which = 'Bottom'
			break;
		case 2:
			_which = 'ItemTitleRegion'
			break;
	}
	if(m_IE){
		baseObj.className=baseObj.className.replace('d' + _which + 'LinkPos','d' + _which + 'LinkPos_Over');
		//_lastLink = baseObj.childNodes(0).className + '_Over';
		//baseObj.childNodes(0).className = _lastLink;
	}else{
		baseObj.className=baseObj.className.replace('d' + _which + 'LinkPos','d' + _which + 'LinkPos_Over');
		//_lastLink = baseObj.firstChild.className + '_Over';
		//baseObj.firstChild.className = _lastLink;
	}
}
function rollOffNavLnk(baseObj){
	if(m_IE){
		baseObj.className=baseObj.className.replace('_Over','');
		//baseObj.childNodes(0).className = _lastLink.replace('_Over','');
	}else{
		baseObj.className=baseObj.className.replace('_Over','');
		//baseObj.firstChild.className = _lastLink.replace('_Over','');
	}
}
function getSiteTheme(){
   var _Theme = eval(getDefaultTheme(oSiteThemes.themes))[0];
   var _CLMarker = 0;
   if(getCookieKey("UserInfo", "CLMarker")!=null){
      _CLMarker = parseInt(getCookieKey("UserInfo", "CLMarker"));
   }
   if(getCookie('Theme')!=null&&getCookie("AuthCookie2")!=null&&_CLMarker>=4){ 
      _Theme = getCookie('Theme');
      if(eval(_Theme).length==2){
         _Theme = eval(_Theme)[0];
      }
   }
	return 'Theme' + _Theme;
}
function getSiteSubTheme(){
   var _Theme = eval(getDefaultTheme(oSiteThemes.themes))[1];
   var _CLMarker = 0;
   if(getCookieKey("UserInfo", "CLMarker")!=null){
      _CLMarker = parseInt(getCookieKey("UserInfo", "CLMarker"));
   }
   if(getCookie('Theme')!=null&&getCookie("AuthCookie2")!=null&&_CLMarker>=4){ 
      _Theme = getCookie('Theme');
      if(eval(_Theme).length==2){
         _Theme = eval(_Theme)[1];
      }
   }
	return _Theme;
}
function getDefaultTheme(oThemes){
   var _base = 0, _style = 0;
   
   for(var i=0; i<oThemes.length; i++){     
      if(oThemes[i].default_theme==true){
         _base = i;
         if(oThemes[i].sub_themes.length>1){
            for(var ii=0; ii<oThemes[i].sub_themes.length; ii++){
               if(oThemes[i].sub_themes[ii].default_theme==true){
                  _style = ii;
                  break;
               }
            }
         }
         break;
      } 
   }
   return '[' + _base + ',' + _style + ']';
}
function setSiteTheme(index,subindex,bRefresh){
   saveCookie('Theme','[' + index + ',' + subindex + ']');
   if(bRefresh){
      //if(confirm('Would you like to view the new theme now?')){
         window.location.href=window.location;
      //}
   }
}
function saveCookie(name,value){
   //alert(name + '=' + value);
   if(name==null && value==null){ return; }
   var oneYear = 365 * 24 * 60 * 60 * 1000;
   var expDate = new Date();		
   expDate.setTime(expDate.getTime() + oneYear);
   var domain = ""; //"domain=localhost/Wincustomize;"
   domain = 'domain=wincustomize.com;';	   
   document.cookie = name + "=" + escape(value) + "; " + domain + " expires=" + expDate.toGMTString(); + "; path=/";	   
}
function preloadimages(){
	for (i=0;i<preloadimages.arguments.length;i++){
		myimages[i]=new Image()
		myimages[i].src=preloadimages.arguments[i]
	}
}
function appendThemeJavaScript(themeFolder){
   var oPageHeader = document.getElementsByTagName("head").item(0);
   if(document.getElementById('_ThemeJavaScript')){ oPageHeader.removeChild(document.getElementById('_ThemeJavaScript')); }
   try{
      var oLinkNode = document.createElement("script");
      oLinkNode.setAttribute("type", "text/javascript"); 
      oLinkNode.setAttribute("src", "http://www.wincustomize.com/js/" + themeFolder + "/custom.js"); 
      oLinkNode.setAttribute("id", "_ThemeJavaScript");
      oPageHeader.appendChild(oLinkNode);
   }catch(e){ }
}


function addDropShaddow(item, type){
   try{
		var _className = 'DynamicDropShadow_';
		//if(m_Moz) return;
		
		switch (type)
		{
			case 0: // Standard
				break;
			case 1: // LinkBar
				_className = 'DynamicDropShadow_LinkBar_'
				break;
			case 2: // Selected Skin View
				_className = 'DynamicDropShadow_SelectedSkin_'
				break;
			case 3: // Sites Home Page
				_className = 'DynamicDropShadow_SiteHomePage_'
			case 3: // Sites Photo Album Page
				_className = 'DynamicDropShadow_SitePhotoAlbum_'
			break;
		}

      var img = document.createElement('img');
      img.id='_FeaturedSkin_Thumb';

      if(item.className != ''){
         img.className = item.className + ' Hand';
      }else{
         img.className = 'Hand';
      }
      img.src=item.src;
      
      if(item.width>0) { img.width=item.width; };
      if(item.height>0) { img.height=item.height; };
      
		if(item.parentNode.nodeName=='SPAN' && item.parentNode.id=='_shadow4'){ //Removes the existing drop shadow.
			var _parentDIV = item.parentNode.parentNode.parentNode.parentNode.parentNode;
			_parentDIV.appendChild(img);
			item.parentNode.parentNode.parentNode.parentNode.parentNode.removeChild(img,_parentDIV);
			return;
		}
        
     var span4 = document.createElement('span');
     span4.id='_shadow4';
     span4.className=_className + '4';
     span4.appendChild(img)
     
     var span3 = document.createElement('span');
     span3.id='_shadow3';
     span3.className=_className + '3';
     span3.appendChild(span4)
     
     var span2 = document.createElement('span');
     span2.id='_shadow2';
     span2.className=_className + '2';
     span2.appendChild(span3)
     
     var span1 = document.createElement('span');
     span1.id='_shadow1';
     span1.className=_className + '1';
     span1.appendChild(span2)
     
     item.parentNode.replaceChild(span1,item);  

   }catch(e){
      //alert('Error passed as: ' + e.message);
   }
}
function selectGallerySearch(mode){
	if(mode==0){
		document.getElementById('_GalleryBasicSearch').className='GallerySearch_OptionsLnk_Selected';
		document.getElementById('_GalleryAdvancedSearch').className='GallerySearch_OptionsLnk';
		document.getElementById('_GalleryAdvancedSearch_Region').className='Hide';
	}else{
		document.getElementById('_GalleryBasicSearch').className='GallerySearch_OptionsLnk';
		document.getElementById('_GalleryAdvancedSearch').className='GallerySearch_OptionsLnk_Selected';
		document.getElementById('_GalleryAdvancedSearch_Region').className='GallerySearch_AdvancedPos';
	}
}

function setTopPageLinks(){
   /*
   try{
      var oSkins        = document.getElementById('_TopSkins');
      var oMasterSkins  = document.getElementById('_TopMasterSkins');
      var oSkinners     = document.getElementById('_TopSkinners');
      var oSites        = document.getElementById('_TopSites');
      var oArticles     = document.getElementById('_TopArticles');
      var sClassName    = 'Top_HeaderLnk_Selected';
      
      switch(queryString("type")) {
	      case 'authors':
   		   oSkinners.className=sClassName;
		      break;
	      case 'sites':
            oSites.className=sClassName;
            break;
         case 'articles':
            oArticles.className=sClassName;
            break;
         default:
	         switch(queryString("search")){
	            case '3':
                  oMasterSkins.className=sClassName;
                  document.getElementById('_TopSkins_HeaderRow').style.visibility='hidden';
                  break;
	            default:
                  oSkins.className=sClassName;
                  break;
            }
      }
   }catch(e){ }
   */
   try{
      var _DDL = document.getElementById('_TopPageNavDDL');
      if(queryString("type")==''){
         _DDL.selectedIndex = getDDLSelectedIndexFromValue(_DDL,'skins');
      }else{
         _DDL.selectedIndex = getDDLSelectedIndexFromValue(_DDL,queryString("type"));
      }
   }catch(e){
   
   }
   
}
function getDDLSelectedIndexFromValue(item,theValue){
   var _return = -1;
   for (var i = 0; i < item.options.length; i++){
      if(item.options[i].value==theValue){
         _return = i;
         break;
      }
   }
   return _return;
}

function fixAdSizes(item){
   if(m_IE){ //Detect IE and add a little extra width/height to it's ad box to support the dropshadow.
      item.style.width=(parseInt(item.style.width)+9) + 'px';
      item.style.height=(parseInt(item.style.height)+5) + 'px';
   }
}

function imageError(item){
   item.src='/images/' + _Theme + '/image.nopreview.gif';
}

function showMotionPreview(oProperties){
   switch (oProperties.VideoType){
		case 'flash':	{
			showFlashVideo(oProperties);
			break 
		}
		case 'avi':	{
			//Call some other method here.
			break 
		}	
	}
}
function selectMediaControlTab(tab){
   var oTab_Photo     = document.getElementById('MediaControls_Tab_Photo');
   var oTab_Video     = document.getElementById('MediaControls_Tab_Video');
   
   var oRegion_Photo    = document.getElementById('MediaControl_Photo');
   var oRegion_Video    = document.getElementById('MediaControl_Video');
   
   oTab_Photo.className = 'MediaControls_Tab';
   oTab_Video.className = 'MediaControls_Tab';

   oRegion_Photo.style.display='none';
   oRegion_Video.style.display='none';
   
   switch (tab){
      case 'photo':
         oTab_Photo.className = 'MediaControls_TabSelected';
         oRegion_Photo.style.display='';
         break;
      case 'video':
         oTab_Video.className = 'MediaControls_TabSelected';
         oRegion_Video.style.display='';
         break;
      default:
         oTab_Photo.className = 'MediaControls_TabSelected';
         oRegion_Photo.style.display='';
         break;
   }
}
function showThemesDropDownList(oThemes){
   var _str = '';
   var _ddl_1 = 'Base Theme: <BR><select id="_BaseTheme" onchange="setSiteTheme(this.options[this.selectedIndex].value,0,true);" Class="MyAccount_DDL">';
   var _ddl_2 = '';
   for(var i=0; i<oThemes.length; i++){
      _ddl_1 += '<option value="' + oThemes[i].id + '" ';
      if(getSiteTheme()==('Theme'+ i)){
         _ddl_1 += 'selected';
         if(oThemes[i].sub_themes.length>1){
            _ddl_2 += '<BR><BR>Sub Style: <BR>';
            _ddl_2 += '<select id="_SubTheme" onchange="setSiteTheme(document.getElementById(\'_BaseTheme\').options[document.getElementById(\'_BaseTheme\').selectedIndex].value,this.options[this.selectedIndex].value,true);" Class="MyAccount_DDL">';
            for(var ii=0; ii<oThemes[i].sub_themes.length; ii++){
               _ddl_2 += '<option value="' + oThemes[i].sub_themes[ii].id + '" ';
               if(getSiteSubTheme()==ii){
                  _ddl_2 += 'selected';
               }
               _ddl_2 += '>' + oThemes[i].sub_themes[ii].name + '</option>';
            }
            _ddl_2 += '</select>';
         }
      }
     _ddl_1 += '>' + oThemes[i].name + '</option>';
   }
   _ddl_1 += '</select>';
   _str += _ddl_1 + _ddl_2;
   return _str;
}