// Javascript JQUERY document

function switchimg(theimg) {

    $("#img-container").empty();

    $("#img-container").append('<img src="'+theimg+'" id="mainimg"/>');


}





function clickshow(thediv) {

    $("#fancy > *").hide();

    $(thediv).show();

}


$(document).ready(function() {
	
 $('#gallery-thumbscontainer div').each(function() {	
	
	 $(this).click(function() {

		$('#gallery-thumbscontainer div').removeClass("thumbactive");

		$(this).addClass("thumbactive");

        });
	
});	
 

	$('#fancy .panel').hide();
		
    $('#thumbscontainer div').each(function(i) {
	
		$('a.anchor').remove().prependTo('#nav-container');
			
        $(this).click(function() {
	
			$('#thumbscontainer div').removeClass("thumbactive");
			
			$(this).addClass("thumbactive");
			
			$('#fancy .panel').hide();
			
            $('#sw'+i).show();

        });

    });

	var myFile = document.location.toString();
	
	if (myFile.match('#')) { // the URL contains an anchor
		
	  // click the navigation item corresponding to the anchor
	  var myAnchor = '#' + myFile.split('#')[1];
	
	  $('#thumbscontainer div a[href="' + myAnchor + '"]').parent().click();
		
	} else {
		
	  // click the first navigation item
	  $('#thumbscontainer div:first').click();
	
	}



//END THUMB SWITCH


    // Changes the feature image and title to the first in order
    $("#parts-closeup").attr({

        src: imgs[1]

    });

    $("#itemtitle").html(itemtitle[1]);

    // Initialize count variable, used to determine paging animation. Is initialized also on each page using the animation.

var count = 0;

switch (pagecount) {

    case 1:

        $("#totalpages").html("1");

        $("#pager-buttons").css("visibility", "hidden");


        break;

    case 2:

        $("#totalpages").html("2");

        break;

    case 3:

        $("#totalpages").html("3");

        break;

    case 4:

        $("#totalpages").html("4");

        break;



    }

    // NEXT button function....
    $("#gonext").click(function() {


        switch (count) {

        case 0:

            if (pagecount == 1) {

                return;

            } else {

                $("#pages").animate({
                    "left":
                    "-=540px"
                },
                "slow");

                count = 1;

                $("#pagenum").html("2");
            }

            break;

        case 1:

            if (pagecount == 2) {

                $("#pages").animate({
                    "left":
                    "+=540px"
                },
                "slow");

                count = 0;

                $("#pagenum").html("1");

            } else {

                $("#pages").animate({
                    "left":
                    "-=540px"
                },
                "slow");

                count = 2;

                $("#pagenum").html("3");
            }


            break;

        case 2:

            if (pagecount == 3) {

                $("#pages").animate({
                    "left":
                    "+=1080px"
                },
                "slow");

                count = 0;

                $("#pagenum").html("1");


            } else {
                $("#pages").animate({
                    "left":
                    "-=540px"
                },
                "slow");

                count = 3;

                $("#pagenum").html("4");
            }

            break;

        case 3:
            if (pagecount == 4) {

                $("#pages").animate({
                    "left":
                    "+=1620px"
                },
                "slow");

                count = 0;

                $("#pagenum").html("1");

                break;

            }


        }

    });

    // PREVIOUS button function....
    $("#goback").click(function() {

        switch (count) {

        case 0:

            if (pagecount == 4) {

                $("#pages").animate({
                    "left":
                    "-=1620px"
                },
                "slow");

                count = 3;

                $("#pagenum").html("4");

            } else if (pagecount == 3) {

                $("#pages").animate({
                    "left":
                    "-=1080px"
                },
                "slow");

                count = 2;

                $("#pagenum").html("3");

            } else if (pagecount == 2) {

                $("#pages").animate({
                    "left":
                    "-=540px"
                },
                "slow");

                count = 1;

                $("#pagenum").html("2");


            } else {

                return;

            }

            break;

        case 3:

            $("#pages").animate({
                "left":
                "+=540px"
            },
            "slow");

            count = 2;

            $("#pagenum").html("3");

            break;

        case 2:

            $("#pages").animate({
                "left":
                "+=540px"
            },
            "slow");

            count = 1;

            $("#pagenum").html("2");

            break;

        case 1:

            $("#pages").animate({
                "left":
                "+=540px"
            },
            "slow");

            count = 0;

            $("#pagenum").html("1");

            break;

        }

    });


    //Hover Functions
    $("#item1").mouseover(

    function() {

        $("#parts-closeup").attr({

            src: imgs[1]

        });

        $("#itemtitle").html(itemtitle[1]);

    }

    );



    $("#item2").mouseover(

    function() {

        $("#parts-closeup").attr({

            src: imgs[2]

        });

        $("#itemtitle").html(itemtitle[2]);
    }

    );


    $("#item3").mouseover(

    function() {

        $("#parts-closeup").attr({

            src: imgs[3]

        });

        $("#itemtitle").html(itemtitle[3]);
    }

    );


    $("#item4").mouseover(

    function() {

        $("#parts-closeup").attr({

            src: imgs[4]

        });

        $("#itemtitle").html(itemtitle[4]);
    }

    );

    $("#item5").mouseover(

    function() {

        $("#parts-closeup").attr({

            src: imgs[5]

        });

        $("#itemtitle").html(itemtitle[5]);
    }

    );

    $("#item6").mouseover(

    function() {

        $("#parts-closeup").attr({

            src: imgs[6]

        });

        $("#itemtitle").html(itemtitle[6]);
    }

    );

    $("#item7").mouseover(

    function() {

        $("#parts-closeup").attr({

            src: imgs[7]

        });

        $("#itemtitle").html(itemtitle[7]);
    }

    );

    $("#item8").mouseover(

    function() {

        $("#parts-closeup").attr({

            src: imgs[8]

        });

        $("#itemtitle").html(itemtitle[8]);
    }

    );

    $("#item9").mouseover(

    function() {

        $("#parts-closeup").attr({

            src: imgs[9]

        });

        $("#itemtitle").html(itemtitle[9]);
    }

    );

    $("#item10").mouseover(

    function() {

        $("#parts-closeup").attr({

            src: imgs[10]

        });

        $("#itemtitle").html(itemtitle[10]);
    }

    );

    $("#item11").mouseover(

    function() {

        $("#parts-closeup").attr({

            src: imgs[11]

        });

        $("#itemtitle").html(itemtitle[11]);
    }

    );

    $("#item12").mouseover(

    function() {

        $("#parts-closeup").attr({

            src: imgs[12]

        });

        $("#itemtitle").html(itemtitle[12]);
    }

    );
});

