$(document).ready(function() {
	
	$('select').each(function() {
		var listType = $('<ul id="'+$(this).attr('id')+'List" class="dropConvert">');
    	
		$(this).find('option').each(function() {
        	$('<li>').text($(this).text()).attr("title", $(this).val()).appendTo(listType);
    	});
    
    	$(this).replaceWith(listType);
	});
	
	$('.dropConvert > li:first').css("padding","0px 8px 0px 8px").addClass("dropDownFirstItem");
	
	$('body').click(function() {
 		$(".dropConvert").animate({height: 28}, 150 );
 	});
	
	$('.dropConvert').live('click', function(event){
    	event.stopPropagation();
 	});
	
    
    $('.dropConvert > li').live('click', function() {
		
        $(".dropConvert").animate({height: 28}, 150 );
		var n = $(this).parent().find("li").length;
        if ($(this).parent().height() > 28) {
            $(this).parent().animate({height: 28}, 150 ); 
			$(this).parent().find("li:first").text($(this).text()).attr('title',$(this).attr('title'));
			
			$("#lbl"+$(this).parent().attr('id')).val($(this).attr("title"));
						
			if ($(this).text() != "Please select how you heard about us:") {$(this).parent().find("li:first").css({'color': "#000", 'font-style': 'normal', 'font-weight': 'bold'});}
			if ($(this).text() == "Know a Bondholder") { $("#bondholderReferal").slideDown();} else {$("#bondholderReferal").slideUp();}
			
			if ($(this).text() == "Other") { $("#otherHeard").slideDown();} else {$("#otherHeard").slideUp();}
			
			if ($(this).text() == "Exhibition") { $("#exhibitionHeard").slideDown();} else {$("#exhibitionHeard").slideUp();}
			
			//transferURL()
        } else {
            $(this).parent().animate({height: 28 * n}, 150 )
		}
		
		
		
		
        return false;
    });
	
	$("#tbBrochureName").focus(function() {
        if ( $(this).val()=="Name") {
            $(this).val('').css({'color': "#000", 'font-style': 'normal', 'font-weight': 'bold'});
        } 
		$(this).css({'background-color':'#d7df23' });      
    });
	
	$("#tbBrochureName").blur(function() {
        if ( $(this).attr("value")=="") {
            $(this).val('Name').css({'color': "#666", 'font-style': 'italic', 'font-weight': 'normal'});
        } 
		$(this).css({'background-color':'#EEEEEE' });    
    });
	
	
	$("#tbBrochureAddress").focus(function() {
        if ( $(this).val()=="Address") {
            $(this).val('').css({'color': "#000", 'font-style': 'normal', 'font-weight': 'bold'});
        }  
		$(this).css({'background-color':'#d7df23' });    
    });
	
	$("#tbBrochureAddress").blur(function() {
        if ( $(this).attr("value")=="") {
            $(this).val('Address').css({'color': "#666", 'font-style': 'italic', 'font-weight': 'normal'});
        }   
		$(this).css({'background-color':'#EEEEEE' });      
    });
	
	
	$("#tbBrochurePostcode").focus(function() {
        if ( $(this).val()=="Post code") {
            $(this).val('').css({'color': "#000", 'font-style': 'normal', 'font-weight': 'bold'});
        }  
		$(this).css({'background-color':'#d7df23' });    
    });
	
	$("#tbBrochurePostcode").blur(function() {
        if ( $(this).attr("value")=="") {
            $(this).val('Post code').css({'color': "#666", 'font-style': 'italic', 'font-weight': 'normal'});
        }    
		$(this).css({'background-color':'#EEEEEE' });     
    });
	
	
	$("#tbBrochureEmail").focus(function() {
        if ( $(this).val()=="Email address") {
            $(this).val('').css({'color': "#000", 'font-style': 'normal', 'font-weight': 'bold'});
        }   
		$(this).css({'background-color':'#d7df23' });   
    });
	
	$("#tbBrochureEmail").blur(function() {
        if ( $(this).attr("value")=="") {
            $(this).val('Email address').css({'color': "#666", 'font-style': 'italic', 'font-weight': 'normal'});
        }      
		$(this).css({'background-color':'#EEEEEE' });   
    });
	
	
	
	$("#tbBrochurePhone").focus(function() {
        if ( $(this).val()=="Telephone number") {
            $(this).val('').css({'color': "#000", 'font-style': 'normal', 'font-weight': 'bold'});
        }   
		$(this).css({'background-color':'#d7df23' });   
    });
	
	$("#tbBrochurePhone").blur(function() {
        if ( $(this).attr("value")=="") {
            $(this).val('Telephone number').css({'color': "#666", 'font-style': 'italic', 'font-weight': 'normal'});
        }      
		$(this).css({'background-color':'#EEEEEE' });   
    });
	
	
	
	$("#tbBHName").focus(function() {
        if ( $(this).val()=="Bondholder name") {
            $(this).val('').css({'color': "#000", 'font-style': 'normal', 'font-weight': 'bold'});
        }    
		$(this).css({'background-color':'#d7df23' });  
    });
	
	$("#tbBHName").blur(function() {
        if ( $(this).attr("value")=="") {
            $(this).val('Bondholder name').css({'color': "#666", 'font-style': 'italic', 'font-weight': 'normal'});
        }      
		$(this).css({'background-color':'#EEEEEE' });   
    });
	
	
	$("#tbBHAddress").focus(function() {
        if ( $(this).val()=="First line of Bondholder address") {
            $(this).val('').css({'color': "#000", 'font-style': 'normal', 'font-weight': 'bold'});
        }     
		$(this).css({'background-color':'#d7df23' }); 
    });
	
	$("#tbBHAddress").blur(function() {
        if ( $(this).attr("value")=="") {
            $(this).val('First line of Bondholder address').css({'color': "#666", 'font-style': 'italic', 'font-weight': 'normal'});
        }      
		$(this).css({'background-color':'#EEEEEE' });   
    });
	
	
	$("#tbBHPostcode").focus(function() {
        if ( $(this).val()=="Bondholder post code") {
            $(this).val('').css({'color': "#000", 'font-style': 'normal', 'font-weight': 'bold'});
        }     
		$(this).css({'background-color':'#d7df23' }); 
    });
	
	$("#tbBHPostcode").blur(function() {
        if ( $(this).attr("value")=="") {
            $(this).val('Bondholder post code').css({'color': "#666", 'font-style': 'italic', 'font-weight': 'normal'});
        }      
		$(this).css({'background-color':'#EEEEEE' });   
    });
	
	
	
	$("#tbMediaCode").focus(function() {
        if ( $(this).val()=="Media Code") {
            $(this).val('').css({'color': "#000", 'font-style': 'normal', 'font-weight': 'bold'});
        }     
		$(this).css({'background-color':'#d7df23' }); 
    });
	
	$("#tbMediaCode").blur(function() {
        if ( $(this).attr("value")=="") {
            $(this).val('Media Code').css({'color': "#666", 'font-style': 'italic', 'font-weight': 'normal'});
        }      
		$(this).css({'background-color':'#EEEEEE' });   
    });
	
	$("#otherHeard").focus(function() {
        if ( $(this).val()=="Please specify") {
            $(this).val('').css({'color': "#000", 'font-style': 'normal', 'font-weight': 'bold'});
        }     
		$(this).css({'background-color':'#d7df23' }); 
    });
	
	$("#otherHeard").blur(function() {
        if ( $(this).attr("value")=="") {
            $(this).val('Please specify').css({'color': "#666", 'font-style': 'italic', 'font-weight': 'normal'});
        }      
		$(this).css({'background-color':'#EEEEEE' });   
    });
	
	
	$("#exhibitionHeard").focus(function() {
        if ( $(this).val()=="Which exhibition?") {
            $(this).val('').css({'color': "#000", 'font-style': 'normal', 'font-weight': 'bold'});
        }     
		$(this).css({'background-color':'#d7df23' }); 
    });
	
	$("#exhibitionHeard").blur(function() {
        if ( $(this).attr("value")=="") {
            $(this).val('Which exhibition?').css({'color': "#666", 'font-style': 'italic', 'font-weight': 'normal'});
        }      
		$(this).css({'background-color':'#EEEEEE' });   
    });
	
	
	
	/* Perhaps change checkbox */
	$("div.customCheckBox").live('click', function(){
		if ($(this).css("background-position") == "0 0") {
			$(this).css("background-position", '30 0');
		} else {
			$(this).css("background-position", '0 0');
		}
	});	
	
	
	
	$('#dataPolicyPopup').live('click', function() {
	if (findoutMore == 'yes') {
  		
			$("<div class='blackout'></div>").hide().css("opacity",0.8).appendTo('body').delay(300).fadeIn( function() {
			currentscrollpos = $(window).scrollTop()
			$("html, body").animate({ scrollTop: 0 }, 500);
			$("<div class='forgottenpassword'></div>").hide().appendTo('#loginform');
			$('.brochureRequestDataPolicy').appendTo('.forgottenpassword');
			$("div.forgottenpassword").delay(500).slideDown();
			
			});
			
			
		} else {
			
			$("div.forgottenpassword").slideUp( function() {
				currentscrollpos = $(window).scrollTop()
				$("html, body").animate({ scrollTop: 0 }, 500);
				$('.brochureRequestForm').appendTo('.forgotContainer');
				$('.brochureRequestDataPolicy').appendTo('.forgottenpassword');
				
				$("div.forgottenpassword").delay(500).slideDown();
				
			});
			
		}
	});
	
	
	
	
	
	
	
	
	$('#ImgBtnCloseDataPolicy').live('click', function() {
  		if (findoutMore == 'yes') {
  		$("div.forgottenpassword").slideUp( function() {
			 
				$('.brochureRequestDataPolicy').appendTo('.forgotContainer');
				$('.forgottenpassword').remove();
				
				$(".blackout").fadeOut( function() {
					$(".blackout").remove();
				});
				
				$("html, body").animate({ scrollTop: currentscrollpos }, 500);
				
				currentscrollpos = 0
				
			
		})
			
		} else {
			
			$("div.forgottenpassword").slideUp( function() {
			
				$('.brochureRequestDataPolicy').appendTo('.forgotContainer');
				$('.brochureRequestForm').appendTo('.forgottenpassword');
				
				$("div.forgottenpassword").delay(500).slideDown();
				$("html, body").delay(500).animate({ scrollTop: currentscrollpos }, 500);
		
				currentscrollpos = 0
			
			})
			
		}
	
	});
	
	
	
	
	$('.prizeDraw').live('click', function() {
		if (findoutMore == 'yes') {
  		
			$("<div class='blackout'></div>").hide().css("opacity",0.8).appendTo('body').delay(300).fadeIn( function() {
			currentscrollpos = $(window).scrollTop()
			$("html, body").animate({ scrollTop: 0 }, 500);
			$("<div class='forgottenpassword'></div>").hide().appendTo('#loginform');
			$('.brochureRequestPrizeDraw').appendTo('.forgottenpassword');
			$("div.forgottenpassword").delay(500).slideDown();
			
			});
			
			
			
		} else {
			
			$("div.forgottenpassword").slideUp( function() {
				currentscrollpos = $(window).scrollTop()
				$("html, body").animate({ scrollTop: 0 }, 500);
				$('.brochureRequestForm').appendTo('.forgotContainer');
				$('.brochureRequestPrizeDraw').appendTo('.forgottenpassword');
				$("div.forgottenpassword").delay(500).slideDown();
			});
		}
	});
	
	
	
	
	$('#ImgBtnClosePrizeDraw').live('click', function() {
  		
		if (findoutMore == 'yes') {
			
			$("div.forgottenpassword").slideUp( function() {
			
				$('.brochureRequestPrizeDraw').appendTo('.forgotContainer');
				$('.forgottenpassword').remove();
				
				$(".blackout").fadeOut( function() {
					$(".blackout").remove();
				});
				
				$("html, body").animate({ scrollTop: currentscrollpos }, 500);
				
			
			})
			
		} else {
		
			$("div.forgottenpassword").slideUp( function() {
					$(".forgottenpassword").css({"width":"940px", "margin-left":"-470px"});
					$('.brochureRequestPrizeDraw').appendTo('.forgotContainer');
					$('.brochureRequestForm').appendTo('.forgottenpassword');
					
					$("div.forgottenpassword").delay(500).slideDown();
					
					$("html, body").delay(500).animate({ scrollTop: currentscrollpos }, 500);
			
					currentscrollpos = 0
				
			});
		
		}
	});
	
	
	
	
	
	$("#brochureToHowItWorks").live('click', function() {
		
		if (findoutMore == 'yes') {
			
			$("<div class='blackout'></div>").hide().appendTo('body').delay(500).fadeTo("fast", 1.0, function() {
					window.location = "/howitworks"
					});
		
		} else {
			$("#selectBoxContainer").fadeOut( function() {
				$("div.forgottenpassword").slideUp( function() {
					$("div.blackout").delay(500).fadeTo("fast", 1.0, function() {
						window.location = "/howitworks"
					});
				});
			});
					
				
		}
	});
	
	
	
	
	
	
});
