var browserIE = false;
var IEversion = false;
$(function () {
	var strapIndex = getCookie('strapIndex');
	var index = parseInt(Math.floor(Math.random() * 4));
	
	if (strapIndex != "" && strapIndex != null && strapIndex != false) {
		index = parseInt(strapIndex);
	}
	else {
		index = Math.floor(Math.random() * 4);
	}

	switch (index) {
		case 0: $('body').attr('id', 'fuschia'); break;
		case 1: $('body').attr('id', 'navy'); break;
		case 2: $('body').attr('id', 'aqua'); break;
		case 3: $('body').attr('id', 'orange'); break;
		default: $('body').attr('id', '');
	}

	setCookie('strapIndex', index, 1);

	if ($.browser.msie) {
		browserIE = true;
		IEversion = $.browser.version;
		if (IEversion < 7) {
			$('.dropdown').mouseover(
					function () {
						$(this).addClass('over');
					}
				)
			$('.dropdown .submenu').mouseout(
					function () {
						$(this).parent().removeClass('over');
					}
				)
		}
	}

	if ($('ul.dropDownNav').length > 0) {
		$('ul.dropDownNav').superfish({
			animation: { slide: 'toggle' },
			autoArrows: false,
			delay: 300
		});
	}

	if ($('#banner')) {
		getBanner(index);
	}
})

function getCookie(c_name) {
	if (document.cookie.length > 0) {
		var i, x, y, ARRcookies = document.cookie.split(";");
		for (i = 0; i < ARRcookies.length; i++) {
			x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
			y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
			x = x.replace(/^\s+|\s+$/g, "");
			if (x == c_name) {
				return unescape(y);
			}
		}
	}
	return false;
}

function setCookie(c_name, value, expiredays) {
	var exdate = new Date();
	exdate.setDate(exdate.getDate() + expiredays);
	document.cookie = c_name + "=" + escape(value) +
	((expiredays == null) ? "" : ";expires=" + exdate.toUTCString());
}

function getBanner(index) {
	var color = '';
	switch (index){
		case 0: color = 'fuschia'; break;
		case 1: color = 'navy'; break;
		case 2: color = 'aqua'; break;
		case 3: color = 'orange'; break;
		default: color = 'fuschia';
	}
	
  var delay = 2000;
  if (browserIE) {
    $('#bnrBG').css({ background: 'url(assets/images/banners/' + color + '/bg.jpg) no-repeat top right' }).show('fade', 1000, function () {
      $('#lrgImg').css({ background: 'url(assets/images/banners/' + color + '/topImgIE.png) no-repeat top right' }).show('drop', 500)
      $('#medImg').css({ background: 'url(assets/images/banners/' + color + '/midImgIE.png) no-repeat top right' }).show('puff', 700)
      $('#smlImg').css({ background: 'url(assets/images/banners/' + color + '/btmImgIE.png) no-repeat top right' }).show('scale', 900, function () {
        $('#bnrIntroTxt').css({ background: 'url(assets/images/banners/' + color + '/introTxt1.png) no-repeat 25px 50%' }).show('puff', 600, function () {
          setTimeout(function () {
            $('#bnrIntroTxt').hide('fade', 'slow', function () {
              $('#bnrIntroTxt').css({ background: 'url(assets/images/banners/' + color + '/introTxt2.png) no-repeat 25px 50%' }).show('puff', 600, function () {
                setTimeout(function () {
                  $('#bnrIntroTxt').hide('fade', 'slow', function () {
                    $('#bnrIntroTxt').css({ background: 'url(assets/images/banners/' + color + '/introTxt3.png) no-repeat 25px 50%' }).show('puff', 600, function () {
                      setTimeout(function () {
                        $('#bnrIntroTxt').hide('fade', 'slow', function () {
                          $('#bnrHdr').css({ background: 'url(assets/images/banners/' + color + '/bnrHdr.png) no-repeat 25px 100%' }).show('puff', 600);
                          $('#bnrTxt').css({ background: 'url(assets/images/banners/' + color + '/bnrTxt.png) no-repeat 25px 0%' }).show('puff', 600);
                        });
                      }, delay);
                    });
                  });
                }, delay);
              });
            });
          }, delay);
        });
      });
    });
  }
  else {
    $('#bnrBG').css({ background: 'url(assets/images/banners/' + color + '/bg.jpg) no-repeat top right' }).show('fade', 1000, function () {
      $('#lrgImg').css({ background: 'url(assets/images/banners/' + color + '/topImg.png) no-repeat top right' }).show('drop', 500)
      $('#medImg').css({ background: 'url(assets/images/banners/' + color + '/midImg.png) no-repeat top right' }).show('puff', 700)
      $('#smlImg').css({ background: 'url(assets/images/banners/' + color + '/btmImg.png) no-repeat top right' }).show('scale', 900, function () {
        $('#bnrIntroTxt').css({ background: 'url(assets/images/banners/' + color + '/introTxt1.png) no-repeat 25px 50%' }).show('puff', 600, function () {
          setTimeout(function () {
            $('#bnrIntroTxt').hide('fade', 'slow', function () {
              $('#bnrIntroTxt').css({ background: 'url(assets/images/banners/' + color + '/introTxt2.png) no-repeat 25px 50%' }).show('puff', 600, function () {
                setTimeout(function () {
                  $('#bnrIntroTxt').hide('fade', 'slow', function () {
                    $('#bnrIntroTxt').css({ background: 'url(assets/images/banners/' + color + '/introTxt3.png) no-repeat 25px 50%' }).show('puff', 600, function () {
                      setTimeout(function () {
                        $('#bnrIntroTxt').hide('fade', 'slow', function () {
                          $('#bnrHdr').css({ background: 'url(assets/images/banners/' + color + '/bnrHdr.png) no-repeat 25px 100%' }).show('puff', 600);
                          $('#bnrTxt').css({ background: 'url(assets/images/banners/' + color + '/bnrTxt.png) no-repeat 25px 0%' }).show('puff', 600);
                        });
                      }, delay);
                    });
                  });
                }, delay);
              });
            });
          }, delay);
        });
      });
    });
  }
}

function clearField(fieldInfo)
{ 
	if (fieldInfo.value == "Search by Keyword")
	{ fieldInfo.value = ""; }
}

function validateSearch(formInfo)
{
	if (formInfo.query.value == "" || formInfo.query.value == "Search by Keyword")
	{
		alert("Type in a search query");
		return false;
	}
	return true;
}


