// JavaScript Document
$(document).ready(function(){
var siteurl = "http://" + document.domain;
	function preload(arrayOfImages) {
		$(arrayOfImages).each(function(){
			$('<img/>')[0].src = this;
			// Alternatively you could use:
			// (new Image()).src = this;
		});
	}
	//alert(document.domain);

	preload([
		siteurl + '/images/skin/find-why-button-on.png',
		siteurl + '/images/skin/search-background-on.png',
		siteurl + '/images/skin/postcode-search-back-on.png',
		siteurl + '/images/skin/view-button-on.png',
		siteurl + '/images/skin/submit-sprite-on.png'
	]);
$('#search-entry, .postcode-search-entry').focus(function(){
	$(this).val('');
});

		$('.faq-box .head').click(function(){
			//$('.faq-detail').hide();
			$(this).next().slideToggle();
		});

$('.postcode-search-button').click(function(event){
	if ($('input:text[name=postcode-search]').val() == 'enter postcode' || $('input:text[name=postcode-search]').val() == ''){
		event.preventDefault();
		alert('Please enter a postcode');
		//return false;
	};
});

$('.more').click(function(){
	//$('.grouped_sites').slideToggle();
	$('.grouped_sites').slideToggle();
});

$('.postcode-search-form-button').click(function(event){
	if ($('input:text[name=postcode-search-form]').val() == 'enter postcode' || $('input:text[name=postcode-search-form]').val() == ''){
		event.preventDefault();
		alert('Please enter a postcode');
		//return false;
	};
});

/*$(".distance-select").selectbox({
	effect: "slide"
	//effect: "fade"
});*/

$(".expand").click(function(){
	$("#driver-rides").slideDown();
});

$(".collapse").click(function(){
	$("#driver-rides").slideUp();
});

$(function() {
    $(".hoverimg")
        .mouseover(function() { 
            var src = $(this).attr("src").replace(".png", "-over.png");
            $(this).attr("src", src);
        })
        .mouseout(function() {
            var src = $(this).attr("src").replace("-over", "");
            $(this).attr("src", src);
        });
});

$(function() {
    $("#video-cta a")
        .mouseover(function() { 
            var src = $("#play-video").attr("src").replace(".png", "-over.png");
            $("#play-video").attr("src", src);
        })
        .mouseout(function() {
            var src = $("#play-video").attr("src").replace("-over", "");
            $("#play-video").attr("src", src);
        });
});

		/*$(function() {
			$('#banner').cycle({ 
				timeout: 20000, 
				speed:   900,
				random: 1
			});
		});*/
/*
$(".scrollable").scrollable({circular: true, mousewheel: true, easing: "swing"}).navigator().autoscroll({
	interval: 6000
});*/

		$(document).ready(function(){
			$("ul.sf-menu").superfish({ 
				pathClass:  'current',
				autoArrows: false
			}); 
		});/**/
		
	var cycle = document.getElementById("pics2");
		if (cycle != null){
		$('.pics2').cycle({
		timeout: 6000 ,	
		delay:  6000, 
		speed: 1500, 
		pause:	1
		});
	}
			
		$(document).pngFix();
		//$(".transparent").pngFix();
		Cufon.set('fontFamily', 'proxima');
		
		$('.loginbox').click(function() {
	      if($(this).val() == "username" || $(this).val() == "password"){			  	
			  $(this).val("");
		  }
		});
		dotree();

}); 
function text_resize(size){
	document.body.style.fontSize=size;
	$.get("ajax/text_resize.php?ajax=true&size="+size);
	set_cufon();
	return false;
}

function switch_view(id){
	var view = $("#view_proposed").html();
	if(view == "View Proposed") {
		$("#ok"+id).css("display","none");
		$("#proposed"+id).css("display","block");
		$("#view_proposed").html("View Live");
	} else {
		$("#ok"+id).css("display","block");
		$("#proposed"+id).css("display","none");
		$("#view_proposed").html("View Proposed");
	}
}

function dotree(){
	$("#tree").treeview({
			collapsed: true,
			//animated: "medium",
			toggle: function(e){
				e.preventDefault();
			},
			control:"#sidetreecontrol",
			persist: "cookie"
			//unique: true
		});
}	

function edit_node(nid,action){
	$('#nodes').html("");
	$('#nodes').load("nodes.php?nid="+nid+"&mode="+action,function(){
																	
	 });
}

function edit_myvbnode(nid,action){
	$('#nodes').html("");
	$('#nodes').load("myvb.php?nid="+nid+"&mode="+action,function(){
																	
	 });
}

function show_msg(msg){
		$('#show_msg').html(msg);
		$('#show_msg').slideDown();
}

function toggleP(me,target) {
	$("#"+me).hide();	
	$("#"+target).fadeIn("slow");	
}

function show_approval(){
	$("#approval").load("admin/approval_list.php").slideDown();
	//$("#approval").;
}

function show_reject(id){
	$("#"+id).slideDown();
	//$("#approval").;
}

function edit_form(fid,action,id){
	$('#nodes').html("");
	$('#nodes').load("forms.php?fid="+fid+"&mode="+action+"&frmid="+id,function(){															
	 });
}

function fbs_click() {
	u=location.href;
	t=document.title;
	window.open("http://www.facebook.com/sharer.php?u="+encodeURIComponent(u)+"&t="+encodeURIComponent(t),"sharer","toolbar=0,status=0,width=626,height=436");
	return false;
}
function welcome() {

    // open a welcome message as soon as the window loads
    Shadowbox.open({
        content:    '/templates/welcome.php',
        player:     "iframe",
        title:      "Welcome to the CUNA Mutual Site",
        height:     335,
        width:      500
    });

}
function set_cufon() {
	Cufon.set('fontFamily', 'interstate');
	Cufon.replace('h2');
	Cufon.replace('h3');
	Cufon.replace('#nav a');
	Cufon.replace('.title', {
	hover: true });
	Cufon.replace('.topmenu', {
	hover: true });
	Cufon.replace('.pagetitle');
	Cufon.replace('#banner_products_sub_title');
	Cufon.replace('#banner_copy_title');
	Cufon.now();
}
