
// random Number Generation

var Found=false
//var Current = new Array()
var MaxValue; //(Example 2 is equal to: 0,1,2)
var NumUnique=3  //The number of unique numbers required
var Count=0
var Current = new Array()


function GetUnique(){
MaxValue = (genPromos.length-1);
NumUnique = (promo2display- specialPromos.length)

	for (i=0;Count<NumUnique;Count++)
    {
      Found=false
      var rndValue = get_random()
      var j=0
      for (j=0;j<Current.length;j++)
      {
        if (Current[j] == rndValue)
        {
          Found=true
          break
        }
      }
      if (Found)
      {
        Count--
      } else {
        Current[Count]=rndValue
      }
    }
	
}

function get_random()
  {
    var ranNum= Math.round(Math.random()*MaxValue);
    return ranNum;
}

//End Random Number


$(document).ready(function(){
buildPromos()
loadPromo() 

});

var promoParent;
var promoCan = new Array();
var promo = new Array();
var promoBkg = new Array();
var promo2display = 3;
var promoTotals 

//var genPromos = new Array ()
//var specialPromos = new Array ()



function populatePromos(){
var rndCt = 0;
	for (i=0; i < promo2display; i++){
		if (i < specialPromos.length){
		var inner = ""
		inner += ("<h1>"+specialPromos[i].headline+"</h1>");
		inner += ("<h2>"+specialPromos[i].subHead+"</h2>");
		inner += ("<p>"+specialPromos[i].bodyText+"</p>");
		inner += ("<a href='"+specialPromos[i].pgLink +"' >"+specialPromos[i].linkText+"</a>");
		promo[i].html(inner)
		promoBkg[i].css({"background" : "#a2968a URL("+specialPromos[i].bkgImg+") no-repeat"})
		
		promo[i].children().each(function(i){
			if ($(this).html() == ""){$(this).remove();}					
			})
		promo[i].hover(function (){
			$(this).next().fadeTo(100, 0.8)},
			function (){
			$(this).next().fadeTo(1000, 0.33);
			});
		}
		else {
		//count the number remaing put in a var
		//randomly select from the genpromos
		var inner = ""
		inner += ("<h1>"+genPromos[rndCt].headline+"</h1>");
		inner += ("<h2>"+genPromos[rndCt].subHead+"</h2>");
		inner += ("<p>"+genPromos[rndCt].bodyText+"</p>");
		inner += ("<a href='"+genPromos[rndCt].pgLink +"' >"+genPromos[rndCt].linkText+"</a>");
		promo[i].html(inner);
		promoBkg[i].css({"background" : "#a2968a URL("+genPromos[rndCt].bkgImg+") no-repeat"})
	
		promo[i].children().each(function(i){
			if ($(this).html() == ""){$(this).remove();}					
			})
		promo[i].hover(function (){
			$(this).next().fadeTo(100, 0.8)},
			function (){
			$(this).next().fadeTo(1000, 0.25);
			});
		
		rndCt++;
		}
	}
displayPromos()	
}
var displayCt = -1;
var showTimer;
function displayPromos(){
	promoParent.show(1000);
	if (displayCt == -1){showTimer = setInterval ("displayPromos()", 500); displayCt++;}
	else if (displayCt == promo2display){clearInterval (showTimer)}
	else{
	//show each promo	
	promo[displayCt].hide()
	promoCan[displayCt].fadeIn(1000)
	promoBkg[displayCt].fadeTo(3000, 0.25, function(){
	$(this).parent().children().first().fadeIn(4000)
	});
	displayCt++	
	}
	
}


function loadPromo(){
var ct4p = 0;
var ct4pbkg = 0;
var height = 400;
promoTotals = ((genPromos.length+specialPromos.length))
if (page == null){
	promoParent = $(".promorow")
	promoParent.children("div.promocan").each(function(i){
		promoCan[i] = $(this);											   
		promo[ct4p] = promoCan[i].children("div.promohome"); ct4p++;
		promoBkg[ct4pbkg] = promoCan[i].children("div.promohomebkg"); ct4pbkg++;
		});
	}

else{
	height = ($("body").innerHeight())
	promo2display = Math.round(height/182)
	if (promo2display <= 2){promo2display = 3;}
	else if (promo2display >= promoTotals){promo2display = promoTotals}
	//find parent
	promoParent = $(".promocol")
	promoParent.html("");
	for (i=0; i < promo2display; i++){
	var pHTML = ("<div class='promocontainer'><div class='promo'></div><div class='promobkg'></div></div>") 	
	promoParent.append(pHTML)	
	}
	promoParent.children("div.promocontainer").each(function(i){
		promoCan[i] = $(this);											   
		promo[ct4p] = promoCan[i].children("div.promo"); ct4p++;
		promoBkg[ct4pbkg] = promoCan[i].children("div.promobkg"); ct4pbkg++;
		});
}
GetUnique()
populatePromos()   
}


//Common



function findSecPage ()
{

var content= ($(".content"))
var head = $("#head")
var logo = $("#logo")
var subNav = $(".sub_nav")
var curSecLink = $("#"+section)
var logoImg = ("images/g_logo_"+section+".jpg")
var headBkg = ("images/bkg_header_"+section+".jpg")
var secButt = ("images/b_"+section+"_2.gif")
var subNavBkg = ("images/bkg_subnav_"+section+".jpg");
var contentBkg = ("images/bkg_content_"+section+".jpg");
var curPglink = $("#"+page);
	if ((page!="home")&&(section!="home"))
	{ 
	
	curPglink.css({"color" : "#3c3e10"})
	subNavBkg = ("images/bkg_subnav_"+page+".jpg");
	contentBkg = ("images/bkg_content_"+page+".jpg");
	if (noBkg)
	{
	
	 subNavBkg = ("images/bkg_subnav_"+section+".jpg");
	 contentBkg = ("images/bkg_content.jpg");
	}
	}
	else if ((page!="home")&&(section=="home"))
	{ 
	
	subNavBkg = ("images/bkg_subnav_"+section+".jpg");
	contentBkg = ("images/bkg_content_"+section+".jpg");
	curPglink.css({"color" : "#3c3e10"})
	content.css({"margin-top" : "-27px"});
	content.css({"padding-top" : "27px"});
	section=page;
	
	}
	else if ((section!="spa")&&(section!="salon")&&(section!="packages")&&(section!="careers"))
	{ 
	
	content.css({"margin-top" : "-27px"});
	content.css({"paddingTop":"27px"});
	}
	
content.css({"background" : "url("+contentBkg+") no-repeat"});
head.css({"background" : "url("+headBkg+") no-repeat"});
subNav.css({"background" : "url("+subNavBkg+") no-repeat"});
logo.attr("src" , logoImg);
	if (curSecLink != null)
	{
	
	curSecLink.src = secButt;
	}
	
}

function toggle(obj) {
	var el = $(obj);
	if ( el.css("display") !=  "none" ) {
		el.css({"display" : 'none'});
	}
	else {
		el.css({"display" : 'block'});
	}
}
function swapImage(id,img)
{
var thisImage = $("#"+id);
thisImage.src = img;

}
function styleElVal (id,el,n)
{
var changeThis = $("#"+id)
changeThis.css({el : n});
}


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

var genPromos = new Array ()
var specialPromos = new Array ()

function promotion (section, head, subhead, bodytxt, linktext, lnk, bkg){
this.section = section;
this.headline = head;
this.subHead = subhead;
this.bodyText = bodytxt;
this.linkText = linktext;
this.pgLink = lnk;
this.bkgImg = ("images/"+bkg);
return this;
	
}

function buildPromos(){
ct4P = 0
genPromos[ct4P] = new promotion("nails","Forever French","Beautiful and Long Lasting", "Try our New Gel Manicure and Pedicure Services that offer a chip Free French Polish.", 
								"Click Here", "salonnails.shtml#french", "bkg_promo_french.jpg"); ct4P++;
genPromos[ct4P] = new promotion("salon","Salon Services","The experience is waiting", 
								"At Visions Salon we pride ourselves on both the quality and variety of services we offer.",
								"Click here for Services", "salon.shtml", "bkg_promo_salon.jpg"); ct4P++;
genPromos[ct4P] = new promotion("spa","Spa Services","A serene getaway of decadent measures & lavish elegance.", 
								"Our services are offered to give the ultimate relaxation and privacy.",
								"Click here for Services", "spa.shtml", "bkg_promo_spa.jpg"); ct4P++;
genPromos[ct4P] = new promotion("packages","Packages &amp; Series","Spend some Time on Yourself", 
								"Great prices on fabulous combinations of our most popular services.",
								"Click here for Package listing", "packages.shtml", "bkg_promo_packages.jpg"); ct4P++;
genPromos[ct4P] = new promotion("giftcard","Gift Cards","Give the gift of Beauty and Rejuvination", 
								"Visions Gift Cards are always a appreciated. All Gift Cards come in a decorative holder." ,
								"Click here purchase", "giftcard.shtml", "bkg_promo_giftcard.jpg"); ct4P++;
genPromos[ct4P] = new promotion("rewards","Join our Rewards Plan","", 
								"As a valued guest, your loyalty is appreciated and to thank you we are now offering Visions Spa Salon Rewards.", 
								"Learn more here", "rewards.shtml", "bkg_promo_rewards.jpg"); ct4P++;
genPromos[ct4P] = new promotion("newsletter","Subscribe to our Newsletter","Loads of Healthful Tips", 
								"The Visions Spa and Salon newsletter is dedicated to you. After all, your well-being is our business", 
								"Sign-up", "subscribe.shtml", "bkg_promo_subscribe.jpg"); ct4P++;
genPromos[ct4P] = new promotion("login","Online Booking","", 
								"If you haven't set-up your own personal account for our online scheduling then you really should.", 
								"Sign-up here", "login.shtml", "bkg_promo_login.jpg"); 
ct4P = 0;

//if special promos put them here 

specialPromos[ct4P] = new promotion("vote","Help us win best day spa in Detroit","Vote &amp; get 20% Off Any New Service!","","Vote Here..." ,"http://wdiv.cityvoter.com/BadgeGo/17959","bkg_promo_vote4us.jpg"); ct4P++;


specialPromos[ct4P] = new promotion("make-up","20% Off Xtreme Lash! ","Till September 31st, 2010", 
								"", 
								"Get Xtreme...", "salonlash.shtml", "bkg_promo_elash.jpg"); ct4P++;

specialPromos[ct4P] = new promotion("make-up","Eyes 101","Great Back to School Package", 
								"", 
								"Learn More...", "makeupart.shtml", "bkg_promo_eyes101.jpg"); ct4P++;


specialPromos[ct4P] = new promotion("index","Visions on WXYZ ch7","Watch this clip from ch7's A Whole New You", 
								"", "Watch Video", "javascript:createVidWindow()", "bkg_promo_wxyz.jpg");  ct4P++;
specialPromos[ct4P] = new promotion("home","Susan G. Komen Race for the Cure","Team Visions Spa Salon Raised over $900.00", 
								"We would like to thank everyone who helped!", 
								"More Here", "race4cure.shtml", "bkg_promo_cure.jpg"); ct4P++;

specialPromos[ct4P] = new promotion("index","Hair For Oil Spills","Help us Help clean-up the Gulf Oil Spill", 
								"Visions Spa Salon is donating all hair clippings to <a href='http://www.matteroftrust.org'>A Matter of Trust</a>.", 
								"Watch Video", "news.shtml", "bkg_promo_oil.jpg");  ct4P++;
specialPromos[ct4P] = new promotion("spa","Coconut Treatments","Returning for Summer 2010", 
								"Enter a tropical paradise of Coconut, Mango and Pineapple", 
								"Click Here", "coconut.shtml", "bkg_promo_coconut.jpg");  ct4P++;

specialPromos[ct4P] = new promotion("spa","Are you Bathing Suit Ready?","","New! Special Pricing and product discounts on a new Firming Spa Treatment for Summer","Limited Time Offer" ,"spabody.shtml#phyto","bkg_promo_phyto.jpg"); ct4P++;

specialPromos[ct4P] = new promotion("nails","Two Week Manicure","New! Two Week Manicure<br />Soak Off Gel Polish","Perfect for the women that demands long-lasting color.","Click Here" ,"salonnails.shtml#twoweek","bkg_promo_2week.jpg");



}

function createVidWindow(){
$(".main").append("<div class='vidwin'><div class='vidbkg'></div><div class='vidclose'><a href='javascript:removeVid()'>X</a></div></div>")

$(".vidwin").append('<object type="application/x-shockwave-flash" id="video" width="640" height="520" data="http://www.wxyz.com/video/videoplayer.swf?dppversion=7657"><param value="http://www.wxyz.com/video/videoplayer.swf?dppversion=7657" name="movie"/><param value="&skin=MP1ExternalAll-MFL.swf&embed=true&adSrc=http%3A%2F%2Fad%2Edoubleclick%2Enet%2Fpfadx%2Fssp%2Ewxyz%2Fmarketplace%2Fa%5Fwhole%5Fnew%5Fyou%2Fdetail%3Bdcmt%3Dtext%2Fxml%3Bsz%3D%25size%25%3Bpos%3D%25pos%25%3Bloc%3D%25loc%25%3Bcomp%3D%25adid%25%3Btile%3D2%3Bfname%3Dvisions%2Dspa%2Dsalon%3Bord%3D554771626725180200%3Frand%3D%25rand%25&flv=http%3A%2F%2Fwww%2Ewxyz%2Ecom%2Ffeeds%2FoutboundFeed%3FobfType%3DVIDEO%5FPLAYER%5FSMIL%5FFEED%26componentId%3D185775411&img=http%3A%2F%2Fmedia2%2Ewxyz%2Ecom%2F%2Fphoto%2F2010%2F06%2F30%2FVisions%5FSpa%5FSalon0bb8b7d3%2D2745%2D4c24%2D83ce%2D831f500e6d370000%5F20100630160553%5F640%5F480%2EJPG&story=http%3A%2F%2Fwww%2Ewxyz%2Ecom%2Fdpp%2Fmarketplace%2Fa%5Fwhole%5Fnew%5Fyou%2Fvisions%2Dspa%2Dsalon" name="FlashVars"/><param value="all" name="allowNetworking"/><param value="always" name="allowScriptAccess"/></object>')

}
function removeVid(){
$(".vidwin").remove();	
	
}