$(document).ready(function() {
  //To hide inner left hand menu for product range Roshan 13 oct 2010
  if ($('#expandNav').length==0) 
  {
     $('#menuInner').css("display", "none");
  }
  else
  {$('#menuInner').css("display", "block");}
  
//END To hide inner left hand menu for product range Roshan 13 oct 2010  

//This function returns querystring parameters
function getUrlVars() {     
var vars = [], hash;     
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); 
    for(var i = 0; i < hashes.length; i++)  
      {         
        hash = hashes[i].split('=');     
        vars.push(hash[0]);      
        vars[hash[0]] = hash[1];
      }     
   return vars; 
   }
   
var first = getUrlVars()["cmspagemode"];
//This check is implemented as when it opens in edit mode in sitefinity it added fancy box to edit mode too by ROSHAN
if(first != 'edit')
 {
      if ($('div#finish-columns1').length) {
    $('div#finish-columns1 img').each(function() {
      $(this).next().attr('href', $(this).attr('src').replace('-small', '-large'));
    });
    $('div#finish-columns1 a').fancybox();    
  };
}
  
  
  if ($('#mycarousel').length) {
    $('#mycarousel').jcarousel({
      vertical: true,
      wrap: 'circular',
      scroll: 4
    });
  };
  
	if ($('input#find-nearest-retailer-postcode').length) {
		$('input#find-nearest-retailer-postcode').snapForm();
	};

  if ($('a#flash-gws').length) {
    $('a#flash-gws').click(function() {
      swfobject.embedSWF("assets/swf/omegaHomepage_gws.swf", "flash-content", "725", "384", "9.0.0", false, false, {wmode:"transparent"}, false);
      return false;
    });
  };
  
  if ($('a#flash-ifs').length) {
    $('a#flash-ifs').click(function() {
      swfobject.embedSWF("assets/swf/omegaHomepage_ifs.swf", "flash-content", "725", "384", "9.0.0", false, false, {wmode:"transparent"}, false);
      return false;
    });
  };  
  
  if ($('a#flash-ivc').length) {
    $('a#flash-ivc').click(function() {
      swfobject.embedSWF("assets/swf/omegaHomepage_ivc.swf", "flash-content", "725", "384", "9.0.0", false, false, {wmode:"transparent"}, false);
      return false;
    });
  };
  
  if ($('a#flash-los').length) {
    $('a#flash-los').click(function() {
      swfobject.embedSWF("assets/swf/omegaHomepage_los.swf", "flash-content", "725", "384", "9.0.0", false, false, {wmode:"transparent"}, false);
      return false;
    });
  };  
  
  if ($('a#flash-sww').length) {
    $('a#flash-sww').click(function() {
      swfobject.embedSWF("assets/swf/omegaHomepage_sww.swf", "flash-content", "725", "384", "9.0.0", false, false, {wmode:"transparent"}, false);
      return false;
    });
  };
  
  if ($('div#product-gallery').length) {
    
    $('div.navigation').css({'width' : '300px', 'float' : 'left'});
    $('div.content').css('display', 'block');

    var onMouseOutOpacity = 0.8;
    $('#thumbs ul.thumbs li').opacityrollover({
      mouseOutOpacity:   onMouseOutOpacity,
      mouseOverOpacity:  1.0,
      fadeSpeed:         'fast',
      exemptionSelector: '.selected'
    });

    
    var gallery = $('#thumbs').galleriffic({
      delay:                     2500,
      numThumbs:                 15,
      preloadAhead:              10,
      enableTopPager:            false,
      enableBottomPager:         false,
      maxPagesToShow:            7,
      imageContainerSel:         '#slideshow',
      controlsContainerSel:      '#controls',
      captionContainerSel:       '#caption',
      loadingContainerSel:       '#loading',
      renderSSControls:          false,
      renderNavControls:         false,
      enableHistory:             false,
      autoStart:                 false,
      syncTransitions:           true,
      defaultTransitionDuration: 900,
      onSlideChange:             function(prevIndex, nextIndex) {
        // 'this' refers to the gallery, which is an extension of $('#thumbs')
        this.find('ul.thumbs').children()
          .eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
          .eq(nextIndex).fadeTo('fast', 1.0);
      },
      onPageTransitionOut:       function(callback) {
        this.fadeTo('fast', 0.0, callback);
      },
      onPageTransitionIn:        function() {
        this.fadeTo('fast', 1.0);
      }
    });
        
  };
  
	/* Mega drop down
	*********************************************************
 	*/
	
	//  Config
	var config = {
	     sensitivity: 1, 			// number = sensitivity threshold (must be 1 or higher)
	     interval: 100, 			// onMouseOver polling interval (ms). Neilson recommends 0.5 second delay)
	     over: megaHoverOver, 		// function = onMouseOver callback (REQUIRED)
	     timeout: 100, 				// number = milliseconds delay before onMouseOut
	     out: megaHoverOut 			// onMouseOut polling interval (ms). Neilson recommends 0.5 second delay)
	};
	
	// Add hover intent to primary navigation menu items
	$("#nav-primary ul li#range").hoverIntent(config); //Trigger Hover intent with custom configurations
			
	// Mega Drop Down Hover Over
	function megaHoverOver(){
	    $(this).find(".megadropdown").stop().show();
	    $(this).find(".navhandle").addClass("hover")
	 }
	 
	// Mega Drop Down Hover Out
	function megaHoverOut(){
	  $(this).find(".megadropdown").stop().hide(); 
	  $(this).find(".navhandle").removeClass("hover");
	}
	  
});


// for quick links
function MM_jumpMenu(targ,selObj,restore){ //v3.0
	  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	  if (restore) selObj.selectedIndex=0;
	}



//Validation for request a broucher

var expTelephone = /[^\d|\.|\,|\-|\+|\(|\)|\" "]+/;
function validation()
{
	if(document.getElementById("name").value.replace(/\s/g,'') == "")	{
			alert("Please make sure the \"Name\" field was properly completed.");
			document.getElementById("name").value="";
			document.getElementById("name").focus();
			return false;
	} else if(document.getElementById("postcode").value.replace(/\s/g,'') == "")	{
			alert("Please make sure the \"Post Code\" field was properly completed.");
			document.getElementById("postcode").value="";
			document.getElementById("postcode").focus();
			return false;
	} else if (document.getElementById("emailaddress").value.replace(/\s/g,'')=="") {
		alert("Please make sure the \"Email Address\" field was properly completed.")
		document.getElementById("emailaddress").focus();
		return false;
	} else if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(document.aspnetForm.emailaddress.value)) {
			alert("This is not a valid email address, Please make sure the \"Email Address\" field was properly completed.")
			document.getElementById("emailaddress").focus();
			return false;
	} else if (document.getElementById("telephone").value.replace(/\s/g,'')!="" && expTelephone.test(document.aspnetForm.telephone.value)==true) {
		alert("Telephone number must be numeric.");
		document.getElementById("telephone").focus();
		return false;
	} else if(confirm("Have you read the privacy policy?")==false) {
		document.getElementById('pp').focus();
		return false;
	}
document.aspnetForm.method="POST";
document.aspnetForm.action="/omega/BrochureThanks.asp";
 $("#aspnetForm").submit();   
	return true;
}

function submitValue(e)
{
    var key;
   var unicode=e.keyCode? e.keyCode : e.charCode
if(unicode== 13)
{
    var btn = document.getElementById("brochuresubmit");
            if (btn != null)
            { 
            //If we find the button click it
               return(validation());
            }

}
}

//END for Validation for request a broucher


//validation for find a postcode

function ValidatForm1()
        {
        
        var ctrPostcode=document.getElementById("FARpostcode");
           if(ctrPostcode.value=='enter postcode')
            {
                alert("Please enter your postcode");
                ctrPostcode.focus();
                return false;
            }

            if(ctrPostcode.value == "")
            {
                alert("Please enter your postcode");
                ctrPostcode.focus();
                return false;
            }
            else if(ctrPostcode.value.replace(/^\s+|\s+$/g,"").indexOf(" ")==-1)
            {


                alert("Postcode is not valid. Please enter a valid postcode");
                ctrPostcode.focus();
                return false;
            }
            
            
            document.aspnetForm.method="POST";
            document.aspnetForm.action="/omega/findaretailer.asp";
            
            $("#aspnetForm").submit();   
           // document.forms["aspnetForm"].submit();
            return false;
    }
        
function GetRef(oId)
 {
  return document.getElementById(oId)
 }


function assignPostCode()
{

          
    if(document.getElementById('FARpostcode').value=='enter postcode')
    {
        document.getElementById('FARpostcode').value=''
   //GetRef("FARpostcode").focus();
      
    }
  
}

function assignPostCode1()
{

    if(document.getElementById('FARpostcode').value=='')
    {
        document.getElementById('FARpostcode').value='enter postcode'
  // GetRef("FARpostcode").focus();
      
    }
  
}

function submitPostcode(e)
{
    var key;
   var unicode=e.keyCode? e.keyCode : e.charCode
if(unicode== 13)
{
    var btn = document.getElementById("find-nearest-retailer-go");
            if (btn != null)
            { 
            //If we find the button click it
               return(ValidatForm1());
            }

}
}

