// Bob's Rod & Tackle :: Global Javascripts //

// Import JS Files //
document.write('<script type="text/javascript" src="/js/jquery.lightbox.js"></script>');
document.write('<script type="text/javascript" src="/js/jquery.simplemodal.js"></script>');
document.write('<script type="text/javascript" src="/js/contact.js"></script>');
document.write('<script type="text/javascript" src="/js/swfobject.js"></script>');
document.write('<script type="text/javascript" src="/js/jquery.uploadify.js"></script>');
document.write('<script type="text/javascript" src="/js/jquery.cycle.all.min.js"></script>');
$(document).ready(function(){
	$(".nav_btn").hover(function() {
		if(!$(this).hasClass('btnon')) {
			$(this).addClass('btnhover');
		}
    },
    function(){
		if(!$(this).hasClass('btnon')) {
			$(this).removeClass('btnhover');
		}
	});
	
	$(".nav_btn").bind("click", function(){
      		var pid = $(this).attr("id");
			window.location = pid;
    });
	
	$("#forum_btn").hover(function() {
        $(this).attr("src", "/images/forum_btn_over.png");
    },
    function(){
        $(this).attr("src", "/images/forum_btn.png");
	});
	$("#forum_btn").bind("click", function(){
		window.location = 'http://www.bobsrodandtackle.com/forum';
    });
	
	$("#contact_btn").hover(function() {
        $(this).attr("src", "/images/contact_btn_over.png");
    },
    function(){
        $(this).attr("src", "/images/contact_btn.png");
	});
	$("#contact_btn").bind("click", function(){
		window.location = '/Pages/Contact';
    });
	
	$('#sibox > span').cycle({
		fx:      'fade',
		speed:   1000,
		timeout: 10000,
		pause:   1
	});
	
	$("#sibox > span > img").live("click", function(){
		window.location = $(this).attr('id');
    });
	
	$("#facebook_btn").hover(function() {
        $(this).removeClass("facebook_btn").addClass("facebook_btn_over");
    },
    function(){
        $(this).removeClass("facebook_btn_over").addClass("facebook_btn");
	}); 
	
	$("#back_to_top").bind("click", function(){
		$('html, body').animate({scrollTop:0}, 1000);
    });
	
	var lbopts = {
		imageLoading: '/images/loading.gif',
		imageBtnClose: '/images/close.gif',
		imageBtnPrev: '/images/prev.gif',
		imageBtnNext: '/images/next.gif'
	};
	
	$('a#photo').lightBox(lbopts);
	$('a#gallery').lightBox(lbopts);
	$('#set1 a').lightBox(lbopts);
	$('#set2 a').lightBox(lbopts);
	$('#set3 a').lightBox(lbopts);
	$('#set4 a').lightBox(lbopts);
	$('#set5 a').lightBox(lbopts);
	$('#set6 a').lightBox(lbopts);
	$('a#bimg_1').lightBox(lbopts);
	$('a#bimg_2').lightBox(lbopts);
	$('a#bimg_3').lightBox(lbopts);
	$('a#bimg_4').lightBox(lbopts);
	$('a#bimg_5').lightBox(lbopts);
	$('a#bimg_6').lightBox(lbopts);
	$('a#bimg_7').lightBox(lbopts);
	$('a#bimg_8').lightBox(lbopts);
	$('a#bimg_9').lightBox(lbopts);
	$('a#bimg_10').lightBox(lbopts);
	$('a#bimg_11').lightBox(lbopts);
	$('a#bimg_12').lightBox(lbopts);
	$('a#bimg_13').lightBox(lbopts);
	$('a#bimg_14').lightBox(lbopts);
	$('a#bimg_15').lightBox(lbopts);
	$('a#bimg_16').lightBox(lbopts);
	$('a#bimg_17').lightBox(lbopts);
	$('a#bimg_18').lightBox(lbopts);
	$('a#bimg_19').lightBox(lbopts);
	$('a#bimg_20').lightBox(lbopts);
	$('a#bimg_21').lightBox(lbopts);
	$('a#bimg_22').lightBox(lbopts);
	$('a#bimg_23').lightBox(lbopts);
	$('a#bimg_24').lightBox(lbopts);
	$('a#bimg_25').lightBox(lbopts);
	$('a#bimg_26').lightBox(lbopts);
	$('a#bimg_27').lightBox(lbopts);
	
	$("div.gallery").bind("click", function(){
		var galleryID = $(this).attr('id');
		var gID = galleryID.split("_");
		window.location = "/Pages/Gallery/Category/"+gID[1];
    });
	
	$(".gallery_picture").bind("click", function(){
		var picID = $(this).attr('id');
		if ( !$(this).hasClass("pic_selected") ) {
   			$(".gallery_picture").removeClass("pic_selected");
			$('#photo_gal').fadeOut('normal');
			$('.pic_load').fadeIn('normal');
			$(this).addClass("pic_selected");
			$.post("/gallery_ajax.php", { func: "load", id: picID }, function(data){
				if(data.code == 0) {
					galleryPreloader(data.Purl, data.pid, data.caption);
				} else if(data.code == 1) {
					$('.pic_load').fadeOut('fast');
					alert(data.msg);
					$('#photo_gal').html('Please Choose a Photo >').fadeIn('fast');
				} else if(data.code == 2) {
					$('.pic_load').fadeOut('fast');
					alert(data.msg);
					$('#photo_gal').html('Please Choose a Photo >').fadeIn('fast');
				}
    			
    		}, "json");
		}
    });
	
	
	$(".wdata_btn").bind("click", function(){
		var btn = $(this);
		var data = $(this).attr('id');
		var img = '';
		$('#wdata > img').slideUp('normal');
		$('<div />').appendTo('#wdata').addClass('wdata_loading');
		$(".wsel").each(function(){
			$(this).animate({"marginLeft": "-10px", "opacity": "0.6" }, 500).removeClass("wsel");
		});
		btn.addClass("wsel").animate({"marginLeft": "-4px", "opacity": "1.0" }, 500);
		var imgs = new Array(5);
		imgs[0] = new Array('http://137.99.198.37/.snap?ledgemet_parse.vi&type=png&quality=100&depth=24', '545px', '492px');
		imgs[1] = new Array('http://pars.dms.uconn.edu/.snap?nlds_parse_met.vi&type=png&quality=100&depth=24', '546px', '489px');
		imgs[2] = new Array('http://137.99.198.39/.snap?clis2_parse_met.vi&type=png&quality=100&depth=24', '548px', '489px');
		imgs[3] = new Array('http://137.99.198.39/.snap?clisbuoy_parse_wave.vi&type=png&quality=100&depth=24', '551px', '349px');
		imgs[4] = new Array('http://images.intellicast.com/WxImages/RadarLoop/hfd_None_anim.gif', '545px', '352px');
		$("<img>").attr("src", imgs[data][0]).css({"display": "none", "width": imgs[data][1], "height": imgs[data][2]}).load(function(){
        	$('.wdata_loading').fadeOut('fast');
			$('#wdata').html('').append($(this)).animate({"width": imgs[data][1], "height": imgs[data][2]});
			$(this).fadeIn('normal');
    	});
    });
	
});

function galleryPreloader(purl, pid, caption) {
		$("<img>").attr({src: purl, id: pid}).css({"width": "500px", "border": "0px"}).load(function(){
        	$('.pic_load').fadeOut('fast');
			$('#photo_gal').html('').append($(this));
			$('#photo_gal').append(caption);
    	});
		$('#photo_gal').fadeIn('fast');
}
function checkUpload() {
	if ($('#agree:checked').val() == null) {
 		alert("Please agree to the rules before uploading!");
		return false;
	} else {
		return true;
	}
}

var newwindow;
function privacyPolicy(){
	newwindow=window.open('/PrivacyPolicy','Privacy Policy','height=450,width=350,scrollbars=yes,toolbar=false,menubar=false,location=false,status=false,directories=false');
	if (window.focus) {newwindow.focus()}
}