var snd;
var size = screen.width*0.7;
var size2 = screen.width*0.8;

$(document).ready(function()
{
resizer();

$('#next').click(next);
$('#previous').click(previous);

});

var licznik = 1;
var weapons = [];

weapons[1] = "images/weapons/glock.png";
weapons[2] = "images/weapons/m3c.png";
weapons[3] = "images/weapons/m249c.png";
weapons[4] = "images/weapons/ak47c.png";

var weaponsName = [];

weaponsName[1] = "Glock";
weaponsName[2] = "M3";
weaponsName[3] = "M249";
weaponsName[4] = "AK47";




function next()
{
licznik++;
$('#weapon').hide("fast");
if(licznik>4) licznik=1;
$('#weapon').attr('src',weapons[licznik]);
$('#weaponName').text(weaponsName[licznik]);
$('#linkWeapon').attr('href',"#"+weaponsName[licznik]);


$('#weapon').show("fast");
}

function previous()
{
licznik--;
$('#weapon').hide("fast");
if(licznik<1) licznik=4;
$('#weapon').attr('src',weapons[licznik]);
$('#weaponName').text(weaponsName[licznik]);
$('#linkWeapon').attr('href',"#"+weaponsName[licznik]);
$('#weapon').show("fast");
}


function glockShot() 
{
var c = document.getElementById("glockId");
var ctx = c.getContext("2d");

var img = new Image();
var img2 = new Image();
img2.src = 'images/weapons/glocka.png';
img.src = 'images/weapons/glockb.png';
ctx.drawImage(img, 0, 0, size, size);


if (counter==2){
	snd = new Audio ('sounds/deagle-1.mp3');
	snd.play();}

setTimeout(function()
	{
	
	ctx.clearRect(0,0,size,size)
	ctx.drawImage(img2, 0, 0, size, size);
	
	},50);
	
}


function m3Shot()
{
var c = document.getElementById("M3Id");
var ctx = c.getContext("2d");

var img = new Image();
var img2 = new Image();
img2.src = 'images/weapons/M3.png';
img.src = 'images/weapons/M3b.png';
ctx.drawImage(img, 0, 0, size, size);


if (counter==2){
	snd = new Audio ('sounds/m3-1.mp3');
	snd.play();}

setTimeout(function()
	{
	
	ctx.clearRect(0,0,size,size)
	ctx.drawImage(img2, 0, 0, size, size);
	
	},50);
	

}

function m249Shot()
{


var c = document.getElementById("M249Id");
var ctx = c.getContext("2d");

var img = new Image();
var img2 = new Image();
img2.src = 'images/weapons/m249.png';
img.src = 'images/weapons/m249b.png';
ctx.drawImage(img, 0, 0, size, size);


if (counter==2){
	snd = new Audio ('sounds/m249-1.mp3');
	snd.play();}

setTimeout(function()
	{
	
	ctx.clearRect(0,0,size,size)
	ctx.drawImage(img2, 0, 0, size, size);
	
	},50);

}



function ak47Shot()
{
var c = document.getElementById("ak47Id");
var ctx = c.getContext("2d");

var img = new Image();
var img2 = new Image();
img2.src = 'images/weapons/Ak47.png';
img.src = 'images/weapons/Ak47s.png';
ctx.drawImage(img, 0, 0, size, size);


if (counter==2){
	snd = new Audio ('sounds/1.mp3');
	snd.play();}

setTimeout(function()
	{
	
	ctx.clearRect(0,0,size,size)
	ctx.drawImage(img2, 0, 0, size, size);
	
	},50);

}





var counter;
function resizer()
{
document.getElementById("container").style.width=size+"px";
document.getElementById("container").style.height=size+"px";

document.getElementById("weapon").style.width=size+"px";
document.getElementById("weapon").style.height=size+"px";

var glck = document.getElementById("glockId");
glck.width=size2;
glck.height=size2;


var m3 = document.getElementById("M3Id");
m3.width=size2;
m3.height=size2;


var m249 = document.getElementById("M249Id");
m249.width=size2;
m249.height=size2;

var ak = document.getElementById("ak47Id");
ak.width=size2;
ak.height=size2;

ak47Shot();
m249Shot(); 
m3Shot();
glockShot();
counter=2;

}

