//document.getElementById("dialogWindow").style.clip = rect;
var js_debug_enabled = 1;
var curtainStep = 10; 
var curtainTimeout = 15;

var curtainLeft = 150;
var curtainRight = 150;
var curtainWidth = 310;

var style_cookie_name = 'site_skin';

function in_array(needle, haystack) 
{
	for (var i = 0; i < haystack.length; i++) {
		if (haystack[i] == needle) {
			return true;
		}
	}
	return false;
}


function curtainToggle()
{
	if (curtainLeft>0) {
		curtainOpen();
	} else if (curtainLeft<curtainRight) {
		curtainClose();
	}
}

function curtainOpen()
{
	try {
		var style = GetCookie(style_cookie_name);
	} catch(x) {}
	if (in_array(style, styleNames)){
		current_style_name = style;
	}
	
	
	for(var i = 0; i < styleNames.length; i++){
		if (styleNames[i] == current_style_name){
			document.getElementById('flag_' + styleNames[i]).style.visibility = 'visible';
		}else{
			document.getElementById('flag_' + styleNames[i]).style.visibility = 'hidden';			
		}
	}


	if (curtainLeft>0)
	{
		curtainRight += curtainStep; 
		curtainLeft -= curtainStep; 
		
		var _style = document.getElementById("dialogWindow").style;
		var rect = 'rect(auto, '+ curtainRight +'px, auto, '+ curtainLeft +'px)';
		_style.clip = rect;
		_style.visibility = 'visible';
		setTimeout(curtainOpen,curtainTimeout); 
	} else {
//		alert ('done')
//		alert(_style.clip);
	}
}

function curtainClose()
{
	if (curtainLeft<curtainRight)
	{
		curtainRight -= curtainStep; 
		curtainLeft += curtainStep; 
		
		var rect = 'rect(auto, '+ curtainRight +'px, auto, '+ curtainLeft +'px)';
		
		document.getElementById("dialogWindow").style.clip = rect;
		
		setTimeout(curtainClose,curtainTimeout); 
	}
}


function clipImg(on)
{

document.getElementById("clipEx1").style.clip=on?'rect(78px 146px 183px 84px)':'auto';
}

/*=======================================================================================================*/


function getAllSheets() {
  //if you want ICEbrowser's limited support, do it this way
  if( !window.ScriptEngine && navigator.__ice_version ) {
  	//IE errors if it sees navigator.__ice_version when a window is closing
  	//window.ScriptEngine hides it from that
    return document.styleSheets; }
  if( document.getElementsByTagName ) {
    //DOM browsers - get link and style tags
    var Lt = document.getElementsByTagName('link');
    var St = document.getElementsByTagName('style');
  } else if( document.styleSheets && document.all ) {
    //not all browsers that supply document.all supply document.all.tags
    //but those that do and can switch stylesheets will also provide
    //document.styleSheets (checking for document.all.tags produces errors [WHY?!])
    var Lt = document.all.tags('LINK'), St = document.all.tags('STYLE');
  } else { return []; } //lesser browser - return a blank array
  //for all link tags ...
  for( var x = 0, os = []; Lt[x]; x++ ) {
    //check for the rel attribute to see if it contains 'style'
    if( Lt[x].rel ) { 
    	var rel = Lt[x].rel;
    } else if( Lt[x].getAttribute ) { 
    	var rel = Lt[x].getAttribute('rel');
    } else { 
    	var rel = ''; 
    }
    if ( typeof( rel ) == 'string' &&
        rel.toLowerCase().indexOf('style') + 1 ) {
      //fill os with linked stylesheets
      os[os.length] = Lt[x];
    }
  }
  //include all style tags too and return the array
  for( var x = 0; St[x]; x++ ) { os[os.length] = St[x]; } return os;
}

function changeStyle() {
//    alert(234);
  for( var x = 0, ss = getAllSheets(); ss[x]; x++ ) {
    //for each stylesheet ...
    if( ss[x].title ) {
      //disable the stylesheet if it is switchable
      ss[x].disabled = true;
    }
    for( var y = 0; y < arguments.length; y++ ) {
      //check each title ...
      if( ss[x].title == arguments[y] ) {
        //and re-enable the stylesheet if it has a chosen title
        ss[x].disabled = false;
      }
    }
  }
  if( !ss.length ) { alert( 'Your browser cannot change stylesheets' ); }
}

	function setStyle(style_name)
	{
//		alert(['setStyle', style_name]);
		try {
			SetCookie(style_cookie_name, style_name, null, '/');
		} catch(x) {
//            alert(x);
        }
		changeStyle(style_name);
		curtainClose();
		try {
			setSkin(style_name);
		} catch(x) {
        }
	}

function SetCookie0(sName, sValue)
{
  date = new Date(2010, 0, 1);
  document.cookie = sName + "=" + escape(sValue) + "; expires=" + date.toGMTString();
}


//
//  Function to create or update a cookie.
//    name - String object containing the cookie name.
//    value - String object containing the cookie value.  May contain
//      any valid string characters.
//    [expires] - Date object containing the expiration data of the cookie.  If
//      omitted or null, expires the cookie at the end of the current session.
//    [path] - String object indicating the path for which the cookie is valid.
//      If omitted or null, uses the path of the calling document.
//    [domain] - String object indicating the domain for which the cookie is
//      valid.  If omitted or null, uses the domain of the calling document.
//    [secure] - Boolean (true/false) value indicating whether cookie transmission
//      requires a secure channel (HTTPS).  
//
//  The first two parameters are required.  The others, if supplied, must
//  be passed in the order listed above.  To omit an unused optional field,
//  use null as a place holder.  For example, to call SetCookie using name,
//  value and path, you would code:
//
//      SetCookie ("myCookieName", "myCookieValue", null, "/");
//
//  Note that trailing omitted parameters do not require a placeholder.
//
//  To set a secure cookie for path "/myPath", that expires after the
//  current session, you might code:
//
//      SetCookie (myCookieVar, cookieValueVar, null, "/myPath", null, true);
//
function SetCookie (name,value,expires,path,domain,secure) 
{
    document.cookie = 
	name + "=" + escape (value) +
	((expires) ? "; expires=" + expires.toGMTString() : "") +
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") +
	((secure) ? "; secure" : "");
 }



function GetCookie(sName)
{
  // cookies are separated by semicolons
  var aCookie = document.cookie.split("; ");
  for (var i=0; i < aCookie.length; i++)
  {
    // a name/value pair (a crumb) is separated by an equal sign
    var aCrumb = aCookie[i].split("=");
    if (sName == aCrumb[0])
      return unescape(aCrumb[1]);
  }

  // a cookie with the requested name does not exist
  return null;
} 

//initStyle();
//alert(current_style_name);

//setStyle(current_style_name);