jQuery(document).ready(function($) {
	
	var isiPad =  navigator.userAgent.match(/iPad/i) != null;
	if(isiPad){
		$("body").addClass("ipad");
	}	
	var FullscreenrOptions = {  width: 1980, height: 1080, bgID: '.bgimg' };
	$.fn.fullscreenr(FullscreenrOptions);
	
	$(window).load(function() {
		$.fn.fullscreenr(FullscreenrOptions);
	});
	
	$('.bgs').cycle({ 
	    fx:    'fade', 
	    speed:  1000,
		timeout:  6000
	});

	function nav(){
	
	var speed = 650;
	
	$("#header ul li a").each(function(index) {
	  
		$(this).append("<span />");
	
	});
	
	$("#header ul li a").hover(function(event) {
		
		$(this).find("span").animate({ opacity: 1 }, { queue: false, duration: speed });
		
	}, function(event) {
		
		$(this).find("span").animate({ opacity: 0 }, { queue: false, duration: speed });
		
	});
	
	}
	
	function footer(){
		
	var speed = 650;
	var initial = $("#footer ul").css('bottom');
	
	$("#footer #footer-btn").hover(function() {
		
		$("#footer ul").animate({
			
		'bottom': '26px'
		
		}, { queue: false, duration: speed });
		
	}, function() {
		
		$("#footer ul").animate({
			
		'bottom': initial
		
		}, { queue: false, duration: speed });
		
	});
		
	}
	
	nav();
	footer();
	
	
	
	// jScroll functions
	if(isiPad){} else {
	var $scrollink = $('.scroll-pane');
		$scrollink.jScrollPane({animateTo:true});
	
		$('a.scrollto').bind(
			'click',
			function()
			{
				var targetElementSelectorString = $(this).attr('rel');
				$scrollink[0].scrollTo(targetElementSelectorString);
				return false;
			}
		);
	}
	
	
	
	window.size = function(){
		var w = 0;
		var h = 0;
	
		//IE
		if(!window.innerWidth)
		{
			//strict mode
			if(!(document.documentElement.clientWidth == 0))
			{
				w = document.documentElement.clientWidth;
				h = document.documentElement.clientHeight;
			}
			//quirks mode
			else
			{
				w = document.body.clientWidth;
				h = document.body.clientHeight;
			}
		}
		//w3c
		else
		{
			w = window.innerWidth;
			h = window.innerHeight;
		}
		return {width:w,height:h};
	}
	function resizeIt(){
	if(isiPad){
		
	}else{	
		
	$("#contentmain").css('height',window.size().height - 130 - 46);
	$("#contentsub").css('height',window.size().height - 220 - 46);
	}
		if($(".page-template-page-details-php, .single-product").length != 0){ //about page
		
		if(isiPad){
			
		} else {	
		$(".scroll-pane, .jScrollPaneContainer").css('height',window.size().height - 490 - 46);
		}
		
		} else {
		if(isiPad){
			
		} else {
		$(".scroll-pane, .jScrollPaneContainer").css('height',window.size().height - 204 - 46);
		}
		
		}
		if(isiPad){} else {
		$(".scroll-pane").jScrollPane({
	
		scrollbarWidth:25,
		scrollbarMargin:10,
		animateTo:true,
		dragMaxHeight:66,
		dragMinHeight:66
	
		});
				
		}
	
	}
	
	if(isiPad){
		$("#footer").hide();
		
	}
	
	$(window).load(function(){
	resizeIt();
	});
	
	$(window).resize(function(){
	resizeIt();
	});
	
	$(".techspecs").addClass("shown");
	$(".description").hide();
	
	$(".swaplinks li a").live('click', function(event) {
		
		//var index = $(".swaplinks li a").index(this);
		var href = $(this).attr('href').replace("#","");
		if(isiPad){
		
			$("#details .shown").hide(function(){

			$("#details ." + href).show().addClass('shown');
			resizeIt();

			}).removeClass("shown");
		
		} else {
		
			$("#details .shown").fadeOut(450, function(){

			$("#details ." + href).fadeIn(450).addClass('shown');
			resizeIt();

			}).removeClass("shown");
			
		}
		
		return false;
	});

	$().piroBox({
			my_speed: 400,
			bg_alpha: 0.7,
			slideShow : true,
			slideSpeed : 4,
			close_all : '.piro_close,.piro_overlay'

	});
	
	function ammoTitle(type){
		
		if(type == "pistols"){
			
			$("#copymain h1").fadeOut(function(){
				$(this).text("Pistols").fadeIn();
			});
			
		} else if(type == "rifles"){
			
			$("#copymain h1").fadeOut(function(){
				$(this).text("Rifles").fadeIn();
			});
			
		} else if(type == "ammo"){
			
			$("#copymain h1").fadeOut(function(){
				$(this).text("Ammunitions").fadeIn();
			});
			
		}
		
	}
	
	if($(".page-template-page-ammunitions-php").length != 0){

		if(location.hash == ""){
			
		} else {
			$("#copymain h1").hide();
		}
		
		$("li.pistols").find("a").attr("href","#pistols"); //remove actual url from the pistols link and replace it with our own
		$("li.rifles").find("a").attr("href","#rifles");
		$("li.ammo").find("a").attr("href","#ammo");
		
		$(".noshow").each(function(index) {

		var weapon = $(this).find("a").text();
		$(this).parent().parent().addClass(weapon);
		$(this).remove();

		});
	
	} else {
		
		$("li.pistols").find("a").attr("href",$("li.ammo a").attr("href") + "#pistols"); //remove actual url from the pistols link and replace it with our own
		$("li.rifles").find("a").attr("href",$("li.ammo a").attr("href") + "#rifles");
	}
	
	$(window).bind('hashchange', function(){
		var theHash = location.hash.replace("#","");
		
		if(theHash == "pistols"){
		//do stuff for pistols
			
			ammoTitle("pistols");
			
			$(".order.rifles").slideUp(function(){
				$(".order.pistols").slideDown(function(){
					resizeIt();
				});
			});
			
			
		} else if(theHash == "rifles") {
		//do stuff for rifles
		
			ammoTitle("rifles");
		
			$(".order.pistols").slideUp(function(){
				$(".order.rifles").slideDown(function(){
					resizeIt();
				});
			});
			
			
		} else if(theHash == "ammo"){
			
			ammoTitle("ammo");
			
			$(".order.pistols, .order.rifles").slideDown(function(){
				resizeIt();
			});
			
			
		}
			
	});

	$(window).trigger('hashchange');
	
	
});
