$(document).ready(function() {

	placeSign('inforowman');

	var oldHomePage = "http://www.justscratchit.com/classic/index.html";
	var samplesDir = 'imagescarosel/carosel/';

	if($.browser.msie){
		if(parseInt($.browser.version) == 6){
	
			$("<div>" + "Your Browser is Internet Explorer " + parseInt($.browser.version) + "<span> - Please use our classic site <a href='" + oldHomePage +"' >here</a>...</span>")
				.appendTo($('#toprow')).css({'height':'50px',
												'width':'300px',
		               							'border':'5px solid red',
		               							'padding':'30px',
		               							'position':'absolute',
		               							'left':'40px',
		               							'top':'40px',
		               							'background-color':'#000',
		               							'font-size':'18px',
		               							'color':'#fff'
		               							});
		}
	}




//************************************************************************************************************************************//
//********    MAIN BLOCK    *******//
//*********************************//
//	var theBrowser = identifyBrowser();
//	if (theBrowser == 'ie6' || theBrowser == 'ie5' ){
//		alert('This site has been optimized for Internet Explorer 7 or higher\n and you are opening this page with \"' + theBrowser + '\", We will redirect you\n to our classic site for better viewing... \n\nThank you and we apologize for any inconvenience!\n\nIf you are running Windows and wish to view the new site you\nmay download \"Safari\" or \"Firefox!\"' );
//		navigate(oldHomePage);
//	}

	var	$sliders = $('#rotoscopeul');
	var	pixPerCarosel = $sliders.find('li').size();
	var pixCount = carosel.length;
	var myRandArr = mkRanNumArr(pixCount,pixPerCarosel);
	var pixWidth = 189;
	var counter = 0;
	
	$('#rotoscopeul').find('img').each(function(){
			aRandNum = myRandArr[counter];
			$(this).attr('src', samplesDir + carosel[aRandNum] + '_f.jpg');
			counter++;
			});

	counter = 0;
	$('#rotoscopeul').find('li').each(function(){
			$(this).css({
					'left' : pixWidth * counter
					});
			counter++;
			});
			
	slidePix('#rotoscopeul');
	setInterval(function (){slidePix('#rotoscopeul')},7000);
		
	$showDiv = $('#results_tips');
	$('#turnkey-tip,#labels-tip,#qty-tip,#prizes-tip,#design-tip,#templates-tip,#variable-tip,#agency-tip,#samples-tip').hover(
		function(){
			switch($(this).attr('id')){
			case 'turnkey-tip':	thisL = 355;thisR = 56;break;
			case 'labels-tip':	thisL = 418;thisR = 87;break;
			case 'qty-tip':		thisL = 342;thisR = 120;break;
			case 'prizes-tip':	thisL = 313;thisR = 153;break;
			case 'design-tip':	thisL = 347;thisR = 184;break;
			case 'templates-tip':	thisL = 313;thisR = 220;break;
			case 'variable-tip':	thisL = 435;thisR = 250;break;
			case 'agency-tip':	thisL = 347;thisR = 285;break;
			case 'samples-tip':	thisL = 303;thisR = 320;break;
			default:
			}
			$showDiv.stop().html(hptips.hptip_begin + hptips.hptip_01 + hptips.hptip_end).animate({'left':thisL,'top':thisR},50).fadeIn('fast');
			$('.tooltiparr').css({'background-position' : '0px 10px'});
			$(this).parent().css({'background-image':'url(images/jsi_home-results-checkmark.png)'});
		},
		function(){
			/**/
		});

	$showDiv.click(
		function(){
			$showDiv.fadeOut();
	});
	

	
	function placeSign(elemId){
		$('#'+elemId).html('<img src=\"imagesigns\/' + allsigns[mkRanNumBot(allsigns.length)] + '\" title=\"Scratch Off Signs\">');
	}
	
	function slidePix(anId){
			$sliders = $(anId).find('li');
			$numSliders = $sliders.size();
			for(i=0; i<$numSliders; i++){
				thisSliderLeft = parseInt($sliders.eq(i).css('left'));
				sliderLeft = thisSliderLeft - pixWidth;
				if (sliderLeft < 0){
					$sliders.eq(i).animate({'left': (sliderLeft)}, 4000, 'swing', function(){
								$(this).appendTo(anId);
								$(this).css({'left':(pixWidth*(pixPerCarosel-1))});
								aRandNum = mkRanNumTop(pixCount);
								$(this).find('img').attr('src', samplesDir + carosel[aRandNum] + '_f.jpg');
							});
				}else{
					$sliders.eq(i).animate({'left': (sliderLeft)}, 4000);
			}
		}	
	}

	
});



//************************************************************************************************************************************//
//********    FUNCTION BLOCK    *******//	
//This prototype is provided by the Mozilla foundation and
//is distributed under the MIT license.
//http://www.ibiblio.org/pub/Linux/LICENSES/mit.license

if (!Array.prototype.indexOf)
{
  Array.prototype.indexOf = function(elt /*, from*/)
  {
    var len = this.length;

    var from = Number(arguments[1]) || 0;
    from = (from < 0)
         ? Math.ceil(from)
         : Math.floor(from);
    if (from < 0)
      from += len;

    for (; from < len; from++)
    {
      if (from in this &&
          this[from] === elt)
        return from;
    }
    return -1;
  };
}



function identifyBrowser() {
  var agent = navigator.userAgent.toLowerCase();
  if (typeof navigator.vendor != "undefined" && navigator.vendor == "KDE" && typeof window.sidebar != "undefined")
  {
    return "kde";
  }
  else if (typeof window.opera != "undefined")
  {
    var version = parseFloat(agent.replace(/.*opera[\/ ]([^ $]+).*/, "$1"));
    if (version >= 7)
    {
      return "opera7";
    }else if (version >= 5)
    {
      return "opera5";
    }
    return false;
  }
  else if (typeof document.all != "undefined")
  {
    if (typeof document.getElementById != "undefined")
    {
      var browser = agent.replace(/.*ms(ie[\/ ][^ $]+).*/, "$1").replace(/ /, "");
      if (typeof document.uniqueID != "undefined")
      {
        if (browser.indexOf("5.5") != -1)
        {
          return browser.replace(/(.*5\.5).*/, "$1");
        }else{
          return browser.replace(/(.*)\..*/, "$1");
      }
     }
     else{
        return "ie5mac";
    }
   }
    return false;
  }
  else if (typeof document.getElementById != "undefined")
  {
    if (navigator.vendor.indexOf("Apple Computer, Inc.") != -1)
    {
      if (typeof window.XMLHttpRequest != "undefined")
      {
        return "safari1.2";
      }
      return "safari1";
    }else if (agent.indexOf("gecko") != -1)
    {
      return "mozilla";
  }
 }
  return false;
}



function mkRanNumTop(aNum){
	return Math.ceil(Math.random()*aNum);
}
function mkRanNumBot(aNum){
	return Math.floor(Math.random()*aNum);
}


function mkRanNumArr(aNum,aCount){
	i=0;
	rNumArr = new Array();
	do {
		thisRandNum = mkRanNumBot(aNum);
		if (rNumArr.indexOf(thisRandNum) == -1){
			rNumArr[i]=thisRandNum;
			i++;
	}}
	while (rNumArr.length < aCount);
	return rNumArr;
}
	