$(document).ready(function(){
	
	//var 
	
	hideShowSlider("#conferenceTopContent",83);
    hideShowSlider("#programmeContent",93);
	
	
	$("#nav_click_subjects").click(function () {
		$("#nav_click_destinations").css("background", "url(/images/shd/nav/search_by_destination.gif)" );
		$("#nav_click_subjects").css("background", "url(/images/shd/nav/search_by_subject.gif)" );
		if ($("#subnav_subjects:first").is(":hidden")) {
			$("#subnav_destinations").slideUp("slow");
			$("#subnav_destinations").queue(function () {
				$("#subnav_subjects").slideDown("slow");
				$("#subnav_subjects").dequeue();
			});
		}
	});
	
	$("#nav_click_destinations").click(function () {
		$("#nav_click_destinations").css("background", "url(/images/shd/nav/search_by_destination_ovr.gif)" );
		$("#nav_click_subjects").css("background", "url(/images/shd/nav/search_by_subject_ovr.gif)" );
		if ($("#subnav_destinations:first").is(":hidden")) {
			$("#subnav_subjects").slideUp("slow");
			$("#subnav_subjects").queue(function () {
				$("#subnav_destinations").slideDown("slow");
				$("#subnav_destinations").dequeue();
			});
		}
	});
	
	$("#conference_more").toggle(function(){
		$(".conference_more_text").slideDown('slow');		
		$("#conference_more").css("background", "url(/images/shd/arrow_less.gif)" )
	},function(){
		$(".conference_more_text").slideUp('slow');
		$("#conference_more").css("background", "url(/images/shd/arrow_more.gif)" )
	});
	
	
	//$(".programme_more_text").slideUp('slow');
	$(".programme_more_text").animate({height:"100px"}, "fast");
	$("#programme_more").css("background", "url(/images/shd/arrow_more.gif)" )
	
	$("#programme_more").toggle(function(){
		//$(".programme_more_text").slideDown('slow');	
		$(".programme_more_text").animate({height:"100%"}, "slow");
		$("#programme_more").css("background", "url(/images/shd/arrow_less.gif)" )
	},function(){
		//$(".programme_more_text").slideUp('slow');
		$(".programme_more_text").animate({height:"100px"}, "slow");
		$("#programme_more").css("background", "url(/images/shd/arrow_more.gif)" )
	});	
	
	
	$("#package_open1").toggle(function(){
			$(".package1").slideDown('slow');		
			$("#package_open1").css("background", "url(/images/conf/detail/package_option_close.gif)" )
		},function(){
			$(".package1").slideUp('slow');
			$("#package_open1").css("background", "url(/images/conf/detail/package_option_open.gif)" )
		});	
		$("#package_open2").toggle(function(){
			$(".package2").slideDown('slow');		
			$("#package_open2").css("background", "url(/images/conf/detail/package_option_close.gif)" )
		},function(){
			$(".package2").slideUp('slow');
			$("#package_open2").css("background", "url(/images/conf/detail/package_option_open.gif)" )
		});	
		$("#package_open3").toggle(function(){
			$(".package3").slideDown('slow');		
			$("#package_open3").css("background", "url(/images/conf/detail/package_option_close.gif)" )
		},function(){
			$(".package3").slideUp('slow');
			$("#package_open3").css("background", "url(/images/conf/detail/package_option_open.gif)" )
		});	
		$("#package_open4").toggle(function(){
				$(".package4").slideDown('slow');		
				$("#package_open4").css("background", "url(/images/conf/detail/package_option_close.gif)" )
			},function(){
				$(".package4").slideUp('slow');
				$("#package_open4").css("background", "url(/images/conf/detail/package_option_open.gif)" )
		});	
		$("#package_open5").toggle(function(){
				$(".package5").slideDown('slow');		
				$("#package_open5").css("background", "url(/images/conf/detail/package_option_close.gif)" )
			},function(){
				$(".package5").slideUp('slow');
				$("#package_open5").css("background", "url(/images/conf/detail/package_option_open.gif)" )
		});	
		$("#package_open6").toggle(function(){
				$(".package6").slideDown('slow');		
				$("#package_open6").css("background", "url(/images/conf/detail/package_option_close.gif)" )
			},function(){
				$(".package6").slideUp('slow');
				$("#package_open6").css("background", "url(/images/conf/detail/package_option_open.gif)" )
		});	
			$("#package_open7").toggle(function(){
					$(".package7").slideDown('slow');		
					$("#package_open7").css("background", "url(/images/conf/detail/package_option_close.gif)" )
				},function(){
					$(".package7").slideUp('slow');
					$("#package_open7").css("background", "url(/images/conf/detail/package_option_open.gif)" )
		});	
			$("#package_open8").toggle(function(){
					$(".package8").slideDown('slow');		
					$("#package_open8").css("background", "url(/images/conf/detail/package_option_close.gif)" )
				},function(){
					$(".package8").slideUp('slow');
					$("#package_open8").css("background", "url(/images/conf/detail/package_option_open.gif)" )
		});	
			$("#package_open9").toggle(function(){
					$(".package9").slideDown('slow');		
					$("#package_open9").css("background", "url(/images/conf/detail/package_option_close.gif)" )
				},function(){
					$(".package9").slideUp('slow');
					$("#package_open9").css("background", "url(/images/conf/detail/package_option_open.gif)" )
		});	
			$("#package_open10").toggle(function(){
					$(".package10").slideDown('slow');		
					$("#package_open10").css("background", "url(/images/conf/detail/package_option_close.gif)" )
				},function(){
					$(".package10").slideUp('slow');
					$("#package_open10").css("background", "url(/images/conf/detail/package_option_open.gif)" )
	});
		
	for (i=1;i<=10;i=i+1) 
	{
		
		$(".package" + i).slideUp('slow');
		$("#package_open" + i).css("background", "url(/images/conf/detail/package_option_open.gif)" )
	}
	
	$('#dialog').jqm();	
	$('#brdialog').jqm({trigger:'.dynReqBroc'});
	
	$(".package1").slideDown('slow');		
	$("#package_open1").css("background", "url(/images/conf/detail/package_option_close.gif)" )

    // quote form tabs
    
    $("#tailorMadeQuote").click(function(){
        $(this).parent().parent().removeClass('genEnq');
    });
    $("#generalEnquiry").click(function(){
        $(this).parent().parent().addClass('genEnq');
    });
    
    // quote form toggle second quote
    $("#toggleQuote2").click(function(){
        $('#tmQuoteForm2').toggle();
        $(this).parent().toggleClass('extended');
    });
});


function confirmPost() {
    confirm("Are you sure you want to receive the brochures by post? You can download them now by using the form above.");
}


// SUPERNAV STUDYLINK FUNCTIONALITY
$(document).ready(function (){

    // navigation functions
    initialiseNav();
    //navImageRollovers();
    
    // ieNavFix();

});

function preloadImages() {
    if (document.images) {
        navPopupTop = new Image(); 
        navPopupTop.src = "/images/navigation/navBoxBtm.png"; 
    
        navPopupBtm = new Image(); 
        navPopupBtm.src = "/images/navigation/navBoxTop.png"; 
    }

}


//  initialiseNav() : initialises the hover states on the nav buttons
function initialiseNav() {
    // add selected state and show the first sub menu
    $('ul.browseBySubject');
    $('#topNavItems #browseBySubject').addClass('selected');
    
    // bind a hover event to each top nav button
    $('#topNavItems a.navHover').bind("mouseenter", function(e) { 
        navigationChange($(this).attr("id")); 
        e.preventDefault();
    });
    
    $('#topNavItems a.navHover').bind("click", function(e) {  
        e.preventDefault();
    });
}

//  navigationChange([element being hovered passed from initialiseNav()]) : changes displayed
//  sub menu and hover state on button
function navigationChange(elementID) {
    // alert(elementID);
    
    //$("ul.subnav li").hide();
    
    $('#topNavItems a.navHover').removeClass("selected");
    $("#" + elementID).addClass("selected");
    
    $('.subnav').css("display","none");
    $('.' + elementID).css("display","block");
    
    operaRefresh();
}

function operaRefresh() {
    if (window.opera) { 
    	//alert($("body").css("position"));
    	if ($("body").css("position") === 'static') {
    		$("body").css("position","relative");
    	} else {
    		$("body").css("position","static");
    	}
    }
}

function hideShowSlider(element,cutOff) {
    if ( $(element).length > 0 ) { 
        // get full height of element
        var elementHeight = $(element).outerHeight();
        
        // alert(element + ": " + $(element).outerHeight());
        // apply a height property to the element, therefore cutting it off
        // alert(elementHeight);

        if (elementHeight > cutOff) {
            $(element).css("height",cutOff + "px");  
            // get the elements class
            elementClass = $(element).attr("class");
            // add a show more link after the element with a class of [elementClassMore]
            $(element).after("<a class='readMore show_more " + elementClass + "More' href='#more' title='Read more'><span>Show all</span></a>");

            // bind a click event to the created link
            $("a." + elementClass + "More").bind("click", function(e) {
                // if its current height is the hidden height, animate to full height, change text to hide and change img bg pos
                if($(element).css("height") == cutOff + "px") {
                    // alert("animating down");
                    // alert(cutOff);                
                    // alert(elementHeight);
                    $(element).css({height:cutOff }).animate({ height: elementHeight}, 750);
                    $(this).children("span").text("Hide");
                    $(this).children("span").css("background-image","url(/images/shd/arrow_less.gif)");
                }
                // otherwise do the opposite
                else {
                    // alert($(this + " span"));
                    $(element).css({height: elementHeight }).animate({ height: cutOff }, 750);
                    $(this).children("span").text("Show all");
                    $(this).children("span").css("background-image","url(/images/shd/arrow_more.gif)");
                }
                e.preventDefault();
            });
        }
    }
}