

function showEvent(hash){
		SetSplashStatus(true);
		hash.w.show();
		$.get(options['url'],options['params'],function (data){
				loadEvent(data);
			}
	);
}

function loadEvent(data){
	if (options['loadCallback']) {
		data = options['loadCallback'](data);
	}
	$('#dialog > div.content').html(data);
	$('#dialog div.content').addClass("frmFeedback");
	SetSplashStatus(false);
	if (options['CancelAction']){
			$(options['CancelAction']).click(function(){
				ClosePopup();
				return false;
			});
			$(options['CancelAction']).show();
	}		
	if (options['DoAction']) {
		$(options['DoAction']).click(submitEvent);
	}
	
	
}




/////////////document ready////////////////

$(document).ready(function() {

    $('#rtools .actions').removeClass('clearfix');


// NAV TOP LEVEL ANCHOR REPLACE FROM FIRST CHECKED DROPDOWN ITEM
	$('#navigation a').click(function(){
		thisLink = $(this).attr('href');
		thisId = $(this).parent().attr('id');
		firstSelected = $('.'+thisId+'.nav_dropdown input.selected:first').next('a').attr('href');
		if (firstSelected == null){
			firstSelected = thisLink;
		};
		window.location=firstSelected;
		return false;
	});
 


// NAV DROP DOWN ON LI A HOVER
    $('.nav_dropdown').hide();
    
    var rolledOver = ""
    
    $('#navigation a span.arrow').mouseenter(function(){
        $('#navigation a').removeClass('highlighted');
        $('.nav_dropdown').hide();
        $('.nav_dropdown').eq($('#navigation a span.arrow').index(this)).show();
        $(this).parent().addClass('highlighted');
        $('#navArea').show();
        rolledOver = $(this).parent();
    });

    $('.nav_dropdown .close_button').css('cursor','pointer').click(function(){
        $('.nav_dropdown').fadeOut();
        $('#navigation a').removeClass('highlighted');
    });
	
	$(".nav_dropdown").mouseleave(function(){ 
		$('.nav_dropdown, #navArea').hide();
		$('#navigation a').removeClass('highlighted');
	});

    $('#navArea').mouseenter(function(){
        $('.nav_dropdown').hide();
        $('#navigation a').removeClass('highlighted');
        $(this).hide();
    });
    
    $('#navigation a').not(rolledOver).mouseenter(function(){
        $('.nav_dropdown').hide();
        $('#navigation a').removeClass('highlighted');
        $('#navArea').hide();
    });
// END NAV DROP DOWN ON LI A HOVER


    
// NAV CUSTOMISER
	// hide all sidenav li's
    $('#sidenav ul li').first().siblings().andSelf().addClass("firstNavItem").hide();

    //to show sidenavs that have no top nav eq. Apply class noTopNav to pages required to show side nav li's
    $('.noTopNav #sidenav ul li').show();
    
    //select all checkboxes
    $(".allNone .all").click(function(){
    	var parentItem = $(this).closest(".nav_dropdown").attr("class").replace(" nav_dropdown","");
    	$('.'+parentItem+' #sidenav ul li.firstNavItem').slideDown();
    	$('.'+parentItem+'.nav_dropdown :checkbox').addClass("selected");
    	$('.'+parentItem+'.nav_dropdown input:checkbox').attr("checked","checked");
    });

    //select no checkboxes
    $(".allNone .none").click(function(){
    	var parentItem = $(this).closest(".nav_dropdown").attr("class").replace(" nav_dropdown","");
    	$('.'+parentItem+' #sidenav ul li.firstNavItem').slideUp();
    	$('.'+parentItem+'.nav_dropdown :checkbox').removeClass("selected");
    	$('.'+parentItem+'.nav_dropdown input:checkbox').attr("checked","");
    });

	//show or hide nav items and classify on click
    $(".nav_dropdown :checkbox").click(showHideNav);
    function showHideNav(){
    	var parentItem = $(this).closest(".nav_dropdown").attr("class").replace(" nav_dropdown","");
    	var Checked	= parseInt($('.'+parentItem+'.nav_dropdown input').index(this));
    	$('.'+parentItem+' #sidenav ul li.firstNavItem:eq('+Checked+')').slideToggle();
		if ($(this).hasClass("selected")) {
			$(this).removeClass("selected")
		}
		else {
			$(this).addClass("selected")
		}
	};

	//save button
    $(".nav_dropdown .save_button").click(function(){
		var parentItem = $(this).closest(".nav_dropdown").attr("class").replace(" nav_dropdown","");
        $('.'+parentItem+'.nav_dropdown .isSaved').fadeIn();
	    setTimeout ( function() {
			$('.'+parentItem+'.nav_dropdown .isSaved').fadeOut();
		}, 1700 );
		saveArray(parentItem);
        return false;        
    });


	//view button
    $(".nav_dropdown .go_button").click(function(){
		var parentItem = $(this).closest(".nav_dropdown").attr("class").replace(" nav_dropdown","");
		thisLink = $('#'+parentItem+' a').attr('href');
		firstSelected = $('.'+parentItem+'.nav_dropdown input.selected:first').next('a').attr('href');
		if (firstSelected == null){
		  firstSelected = thisLink;
		};
		window.location=firstSelected;
		saveArray(parentItem);
        return false;        
    });


	//save selected items into array
	function saveArray(parentItem){
        var choices=new Array();
        $('.'+parentItem+'.nav_dropdown input').each(function(i){
            if ($(this).hasClass("selected")){
                choices[i]="selected";
            }
            else {
                choices[i]="notSelected";
            };
        });
        $.cookie(parentItem+'-choices', choices, {expires:365, path: '/'});
	};


	// retrieve from array and apply classes to checkboxes
    $('.nav_dropdown').each(function(){
    	var thisDrop = $(this).attr('class').replace(" nav_dropdown","");
    	buildDrop(thisDrop);
    });
	function buildDrop(thisDrop){
	    $("."+thisDrop+".nav_dropdown input").each(function(i){
	    	choices = thisDrop+"-choices"
	        if ($.cookie(choices)){
				var returnedChoices=$.cookie(choices);
	    		returnedChoices = returnedChoices.split(",");
		        if (returnedChoices[i]=="selected"){
		          $(this).addClass("selected");
		        }
		        else {
		        $(this).removeClass("selected");
		        };
	    	};
	    });
	};



	//sidenav builder from items with class selected and check the checkbox    
    $('.nav_dropdown').each(function(){
    	var thisDrop = $(this).attr('class').replace(" nav_dropdown","");
    	buildSideNav(thisDrop);
    });
    function buildSideNav(sectionClass){
	    $('.'+sectionClass+'.nav_dropdown input').each(
	    	function(){
	    		if ($(this).hasClass("selected")){
	    			var Checked	= parseInt($('.'+sectionClass+'.nav_dropdown input').index(this));
	    			$('.'+sectionClass+' #sidenav ul li.firstNavItem:eq('+Checked+')').show();
	    			$(this).attr("checked","checked");
	    		}
	    	}
	    );
    };
// END NAV CUSTOMISER


if ($(".summaryHighlights").length >0) {
		$(".summaryHighlights").jcarousel({
        scroll: 1,
        initCallback: mycarousel_initCallback,
        // This tells jCarousel NOT to autobuild prev/next buttons
        buttonNextHTML: null,
        buttonPrevHTML: null
    });
}


//table row hover
	$("table tbody tr").not($("table.noHover tbody tr"))
	.mouseover(function(){
	  $(this).addClass("rowhover");
	}).mouseout(function(){
	  $(this).removeClass("rowhover");
	});


//BACK TOP 
	var mainHeight = $("#main-content").height();
	if (mainHeight <= 700) {
		$('p.backtotop').remove();
	};
	
	$('p.backtotop a').click(function(){
		return false		
	});


//SEARCH BOX TEXT REPLACE
	$('input#zoom_searchbox').bind('focus',
	   function()
	   {
	    if ($(this).attr('value') == 'Search')
	    {
	     $(this).attr('value', '');
	    }
	   });


//CRUMTRAIL, CHANGE BG IF 3 LEVELS
	var crumbLength = $('#crumbtrail ul li').length;
		
	if (crumbLength > 3){
		$('#crumbtrail ul li.cb_item2').addClass("likeFirst");
	};


// ACCORDIAN UI INIT
	$("#accordion").accordion({
		autoHeight: false, 
		collapsible: false, 
		active: 0
	});

	$("#sideAccordion").accordion({
		autoHeight: false, 
		collapsible: true, 
		active: false
	});

	$("#navAccordion").accordion({
		autoHeight: false, 
		collapsible: true, 
		active: 0
	});



//ADDISON DEFAULT ACCORDION

if ($('.accordion').length != 0) {

                $('.accordion h3').next("div").each(function(){

                                                                if ($('body').css('minWidth')==undefined){

                                $(this).attr("rel",$(this).height()+30);

                                                                } else {

                                                                                $(this).attr("rel",$(this).height());

                                                                };

                });

                // Open first one

                $('.accordion h3:first').next('div');

                $('.accordion h3')

                                .each(function(){

                                                $(this).next("div").css("height","0");

                                                $(this).next("div").addClass("closedAccordion");

                });

                $('.accordion h3').live("click",function(){

                                accordion($(this),".accordion h3","",$('.accordion h3').index(this));

                                activeAccSubSection = false;

                                return false;

                });           

};

// END ADDISON DEFAULT ACCORDION


// variable for accordion section
activeAccSubSection = false;
// variable for accordiion subsection and anchor
activeAccSubSectionAnchor = false;
	


$('a.full').click(function(){
	window.open(this.href);
	return false;
});

// if back button rememberance go to that point in page
if (location.hash){	
	
	// remove the # (the hash can container either a number or text)
	var activeAcc=(location.hash).replace('#','');
	// test to find subsection anchor
	activeAccSubSectionTest = activeAcc.indexOf('=');
	activeAccSubSection = false;	
	// if test is true
	if(activeAccSubSectionTest != '-1'){
		
		// split the varibale example 2(accordion sub section) and animal(anchor within subsection)
		activeAccSubSection = activeAcc.split('=', [2]);
		// place sub section accordion varibale within activeAcc
		activeAcc = activeAccSubSection[0];
	} else {
			
		// else test if activeAcc is either a number or text
		if(/^\d*$/.test(activeAcc)){
			// if a number turn into a interger
			
			activeAcc=parseInt(activeAcc);
		} else {
			// else activeAcc is a text anchor
			activeAccSubSectionAnchor = activeAcc;
		}
	}
	activeAcc=parseInt(activeAcc);
	if(activeAccSubSectionAnchor){
		// them scroll to anchor
		$(window).scrollTo($('#'+activeAccSubSectionAnchor), 800 );
	} else {
		
		accordion($('.accordion h3').eq(activeAcc),".accordion h3","true",activeAcc);	
	}
}
	
	

// Accordion function with options - pass in the object (Header) thats been clicked		
function accordion(element,header,type,index){
		$('.accordion h3').each(function(){
			if($(this).hasClass('open')){
				$(this).removeClass("open");
			}
		});
	var height=element.next("div").attr('rel');
	if (element.hasClass("ui-state-active")){
		
		element.next("div").animate({
			height: "0"		
		}, 500).addClass("closedAccordion").prev(header).removeClass("ui-state-active").removeClass('open');
	} else {
		element.next("div").animate({
			height: height
		}, 500,function(){
			if(type != 'false'){
				if(!activeAccSubSection){
					$(window).scrollTo( $(header).eq(index), 800);
				} else {
					$(window).scrollTo( $('#'+activeAccSubSection[1]), 800);
				}
			}
		}).removeClass("closedAccordion").prev(header).addClass("ui-state-active").addClass('open');
	};
};	

// End Accordion function with options - pass in the object (Header) thats been clicked


$('#main-content a').click(function(){
	theLink = false;
	theLink = $(this).attr('href');
	theLinkTest = theLink.indexOf('#');
	if(theLinkTest != '-1'){
		var splitHash = $(this).attr('href').split('#');
			// remove #
			var activeAcc=splitHash[1];	
			// test to find subsection anchor
			activeAccSubSectionTest = activeAcc.indexOf('=');
			activeAccSubSection = false;
			// if test is true
			if(activeAccSubSectionTest != '-1'){
				// split the varibale example 2(accordion sub section) and animal(anchor within subsection)
				activeAccSubSection = activeAcc.split('=', [2]);
				// place sub section accordion varibale within activeAcc
				activeAcc = activeAccSubSection[0];
			}
			// test if activeAcc is either a number or text
			if(/^\d*$/.test(activeAcc)){
				activeAcc=parseInt(activeAcc);
				$(window).scrollTo($('body'), 800, function(){
						// if a sub section with a anchor exist then scroll that anchor after accordion has opened correct section
						isclosed = $('.accordion h3').eq(activeAcc).next().hasClass('closedAccordion');
						if(activeAccSubSection){
							if(isclosed){
								accordion($('.accordion h3').eq(activeAcc),".accordion h3","true",activeAccSubSection[1]);
							} else {
								$(window).scrollTo( $('#'+activeAccSubSection[1]), 800);
							}
						} else {
							// if no anchor within a sub section exist then scroll to open accordion
							if(isclosed){
								accordion($('.accordion h3').eq(activeAcc),".accordion h3","true",activeAcc);
							} else {
								$(window).scrollTo( $('.accordion h3').eq(activeAcc), 800);
							}
						}
				});
			} else {
				// if #hash change was for a anchor within already open accordion then just go the right anchor without any accodion effect 
				$(window).scrollTo($('#'+activeAcc), 800 );
			}
	}
});


	
try{
//HERO SLIDER V1
	var aWidth = $('.heroSlider li a').width();
	var lWidth = $('.heroSlider li.active').width();
	$('.heroSlider li').width(aWidth);
	$('.heroSlider li.active').children('a').addClass('selected');
	$('.heroSlider li.active').width(lWidth).removeClass('active');
	$('.heroSlider li').click(function(){
		//var clickedUrl = $(this).children('a').attr('href');
		var clickedLink = $(this).children('a');
		$('.heroSlider li').removeClass('active');
		$('.heroSlider li a').removeClass('selected');
		$(clickedLink).addClass('selected');
		$(this).animate({width:lWidth},{queue:false, duration:600, easing:'swing'
		//,complete:function(){window.location=clickedUrl;}
		});
		$('.heroSlider li').not(this).animate({width:aWidth},{queue:false, duration:600, easing:'swing'});
		return false;
	});
//END HERO SLIDER
}catch(ex){};



//shareThis popup
	
$('#shareIt').hide();

$('#sideAccordion li#share a').click(function(){
	$('#shareIt').show();
		if(typeof document.body.style.maxHeight === "undefined") {
		        
		} else {
			return false;
		}
});

function closeShare(){
	$('#shareIt').fadeOut();
	return false;
};	

$(document).keyup(function(e) {
  if (e.keyCode == 27) { closeShare() }   // esc
  popOpen = 0;
});

$('#shareIt a.close, #shareBg').click(closeShare);	









/* End including */

	var DoEmailPageLoad = function (data){
	   var tmp = null;
	   if (PageData != null) tmp = DoGSR(data);
	   return tmp;
	};
	$('li#email a').click(function(){
				options = {url: mailerUrl,params: {pg:getPageFromLink('li#email a')},CancelAction: '#CancelSend',DoAction: '#ActionSend', submitCallback: DoEmailPageSubmit, loadCallback: DoEmailPageLoad, submitCQCallback: DoSendEmailFromCq};
				displayPopup();
				return false;		
	});  
	var DoFeedbackPageSubmit = function (){
	   if (PageData != null){
	        var valid = true; 
			if (valid){
				SetSplashStatus(true);
				// send email
				//Included by Stephan Pannier (Logica) to trigger the Feedback event
				if (options['submitCQFeedbackCallback'] != null) options['submitCQFeedbackCallback']();
				$('#dialog div#rtbody').hide();
				$('#dialog div#rtresponse').show();
				SetSplashStatus(false);
			}
	   }
	};
	var DoFeedbackPageLoad = function (data){
	   var tmp = null;
	   if (PageData != null) tmp = DoGSR(data);
	   return tmp;
	};
	
	$('li#feedback a').click(function(){
				options = {url: feedbackUrl,params: {}, CancelAction: '#CancelSend',DoAction: '#ActionSend', submitCallback: DoFeedbackPageSubmit, loadCallback: DoFeedbackPageLoad, submitCQFeedbackCallback: DoSendFeedbackFromCq};
				displayPopup();
				return false;		
	});  
	var DoExitPageLoad = function (data){
	   var tmp = null;
	   if (PageData != null) tmp = DoGSR(data);
	   return tmp;
	};


$("a[href ^= 'http://']").click(function(){
	      if (document.location.href.indexOf("search/search.html") == -1 || $(this).parent().attr("class") != "result_pages"){
				if ($(this).attr("href").indexOf("vodafone.com") > -1) exitUrl = basepath+'scripts/exit1.html';
				else exitUrl = basepath+'scripts/exit.html';
				options = {url: exitUrl,params: {}, CancelAction: '#ActionCancel', loadCallback: DoExitPageLoad};
				PageData = {id:0, name: $(this).attr("href"), path: $(this).attr("href")};
				displayPopup();
				return false;	
		  }				
	});  
	$("a[href ^= 'https://']").click(function(){
		if (document.location.href.indexOf("search/search.html") == -1 || $(this).parent().attr("class") != "result_pages"){
				if ($(this).attr("href").indexOf("vodafone.com") > -1) exitUrl = basepath+'scripts/exit1.html';
				else exitUrl = basepath+'scripts/exit.html';
				options = {url: exitUrl,params: {}, CancelAction: '#ActionCancel', loadCallback: DoExitPageLoad};
				PageData = {id:0, name: $(this).attr("href"), path: $(this).attr("href")};
				displayPopup();
				return false;	
		}				
	});  


	
	$("li#print-basket > a:first").click(function(){
		if (!isInCart()){
			var pg = getPageFromLink('li#email a');
			if (basket != "") 
				basket += "-"+pg;
			else
				basket = pg;
			setCartPageStatus();
		}	
		$.cookie("pbar2010", basket, {expires:365, path: '/'});	
		return false;
	});
	$("#cmdDel").click(function(){
				var tmp = "-"+basket+"-";
				var update = false;
				$("#notelist input[name = 'item']").each(function() {
						var child = $(this);
						if (child.attr('checked') != "") {
							tmp = tmp.replace("-"+child.attr("value")+"-","-");
							update = true;
						}
				});
				if (update) {
					if (tmp.substring(0,1) == "-") tmp = tmp.substring(1);
					if (tmp.substring(tmp.length-1) == "-") tmp = tmp.substring(0,tmp.length-1);
					basket = tmp;
					$.cookie("pbar2010", basket, {expires:365, path: '/'});	
					DisplayBasketPages(".BasketContents");
				}
				return false;
			});
			$("#cmdPrint").click(function(){
				var tmp = "";
				$("#notelist input[name = 'item']").each(function() {
						var child = $(this);
						if (child.attr('checked') != "") tmp += "-"+child.attr("value");		
				});
				if (tmp != "") {
					tmp = tmp.substring(1);
					var link = $(this).attr("href");
					var posq = link.indexOf("?");
					if (posq > -1) link = link.substring(0,posq);
					$(this).attr("href",link+"?print="+tmp);
									
					document.location.href=$(this).attr("href").attr("target", "_blank");
				}

				return false;
			});
	$("#sideAccordion").show();
	setCartPageStatus();
/*Report tools initialisation code - ends here*/	



/*AJAX Notes*/
$('div table.ajaxMe tr td a').live("click",function(){
   if ($(this).attr("class") == "printrow") return true;     
       
   $.get($(this).attr('href'),
   function(data){
    var returnedNote=data;
    var pos1=data.indexOf('<!--begin note-->');
    var pos2=data.indexOf('<!--end note-->');
    
    returnedNote=returnedNote.slice(pos1+17,pos2)
    $('div.new_note').remove();
    $('#main-content').append('<div class="new_note">'+returnedNote+'</div>');
	$('.new_note').css('padding','7px').css('clear','both');
	$.scrollTo($('.new_note'), 800)
       });
       
        return false;
    });
    
    
});
