/* use a cookie to only show header flash once */
// var FLASHPIECE_INDEX = "ONCE"; // "Y","N", or "ONCE"
// var FLASHPIECE_TESTIM = "ONCE"; // "Y","N", or "ONCE"
// 

if(!varIsDefined('FLASHPIECE_INDEX')) {
  var FLASHPIECE_INDEX = 'N';
}
/*if(!varIsDefined('FLASHPIECE_TESTIM')) {
  var FLASHPIECE_TESTIM = 'N';
}
*/


/*
  Get_Parm read value from url str (given key)
*/
function Get_Parm(name) {
    SCH = addCPArgs(document.location.search);    // alert('SCH = ' + SCH);
    var start = SCH.indexOf(name+"=");
    var len = start+name.length+1;
    if ((!start) && (name != SCH.substring(0,name.length))) return null;
    if (start == -1) return null;
    var end = SCH.indexOf("&",len);
    if (end == -1) end = SCH.length;
    return unescape(SCH.substring(len,end));
}
function varIsDefined(variable) {
  return (typeof(window[variable]) == "undefined") ?  false: true;
}
function isObject(a) {
    return (a && typeof a == 'object');
}

/* BEGIN COOKIE FUNCTIONS
  functions to help us set and get cookies, 
*/

function SetCookie (name, value) {
        var argv = SetCookie.arguments;
        var argc = SetCookie.arguments.length;
        var expires = (argc > 2) ? argv[2] : null;
        var path = (argc > 3) ? argv[3] : null;
        var delay = (argc > 4) ? argv[4] : null;
        var secure = (argc > 5) ? argv[5] : false;
        document.cookie = name + "=" + escape (value) +
        ((expires == null) ? "" : ("; expires=" + expires)) +
        ((path == null) ? "" : ("; path=" + path)) +
        ((delay == null) ? "" : ("; delay=" + delay)) +
        ((secure == true) ? "; secure" : "");
}
function SimpleCookie (cookieName, cookieValue, expires_in_minutes,path) {
  var expDate = new Date();
  expDate.setTime( expDate.getTime() + (expires_in_minutes * 60 * 1000) );
  SetCookie(cookieName,cookieValue,expDate.toGMTString(),path);
}

function GetCookie(Name) {
  var search = Name + "="
  var returnvalue = "";
  if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    if (offset != -1) { // if the cookie exists
      offset += search.length
      end = document.cookie.indexOf(";", offset); // set the index of beginning value
      if (end == -1) // set the index of the end of cookie value
        end = document.cookie.length;
      returnvalue=unescape(document.cookie.substring(offset, end))
    }
  }
  return returnvalue;
}
function DeleteCookie (name) {
	var exp = new Date();
	exp.setTime (exp.getTime() - 1);
	var cval = GetCookie (name);
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
/* END COOKIE FUNCTIONS */

/* BEGIN flash cookie functions */

function flashShownAlready(flash_codename) {
  var cookiename = '_FlashPieceShown_' + flash_codename;
  var cookievalue = GetCookie(cookiename);
  if(cookievalue == 'Y') {
    return true;
  } else {
    return false;
  }
}

function flashShownSetCookie(flash_codename) {  
  var cookiename = '_FlashPieceShown_' + flash_codename;
  var expMinutes = 180;
  SimpleCookie (cookiename, "Y", expMinutes,"/");  
}
/* END flash cookie functions */


  


// start videoplayer functions: INDEX:
function startHeaderFlash(flvFile) {
    if(flvFile == "") {
      flvFile = "/flash/hiphopabs_comp1.flv";
    }
    var flashvars = {
    	replayTimeOffset: 10,
    	//replayButtonImage: "/flash/tfb_v2_vidheader_button.swf",
    	//replayButtonPosition: "0|328",
    	//replayButtonLabel: "Replay Video",
  	 	replayButtonImage: "/images/video_replay.jpg",
    	replayButtonPosition: "0|0",
		controlsEnabledTimeOffset: 7,
    	controlsDisabledTimeOffset: 7,
    	loop: false,
		autoPlay: true,
    	buttons:[
    		//"23|323|290|5000||/flash/tfb_flexvid_orderbut.swf|secureorder.php"			
			//"15|300|290|5000||images/vid_order_now.png|secureorder.php"
    		//"10|10|25|35|Button Text|test2.jpg|http://www.cnn.com"
    	],
  		videoUrl:flvFile
	};
	var params = {
   		bgcolor:"#ffffff",
   		wmode:"transparent"
	};
	var attributes = {
	};


  swfobject.embedSWF("/MMVideoPlayer_multi.swf", "indexvid", "100%","100%", "9.0.124","playerProductInstall.swf", flashvars, params, attributes);
}


// start the execution of our flashes codenamed INDEX and TESTIM:


if(FLASHPIECE_INDEX == "Y") {  
  startHeaderFlash("");
} else if(FLASHPIECE_INDEX == "ONCE") {
  if(!flashShownAlready('INDEX')) {
    startHeaderFlash("");
    flashShownSetCookie('INDEX');
  }
} else {
  // noop
}



