
$(document).ready(function() {



	//$('').appendTo('#home_page_image_container');
	$.fn.fadeToggle = function(speed, easing, callback) {
   		return this.animate({opacity: 'toggle'}, speed, easing, callback);
	};


    $('#home_text_overlay').hide();

 	$('#home_text_button').html('<p>Artist Information</p>');
		
	$('#home_text_button').click(function() {
										  
										  $('#home_text_overlay').fadeToggle();
										  
										  if ($('#home_text_overlay').css('opacity')==0) {
										      $('#home_text_button').html('<p>Hide Information</p>');
											  } else {
										      $('#home_text_button').html('<p>Artist Information</p>');
												  }
										  });
	
	

    $("#landing_links ul li a").mouseover(function() {
        $(this).animate({ "opacity": "0.4" }, "fast", function() {
        });
    });
    $("#landing_links ul li a").mouseout(function() {
        $(this).animate({ "opacity": "1.0" }, 10, function() {
        });
    });

    $("#departmentLinks li a").mouseover(function() {
        $(this).animate({ "opacity": "0.4" }, "fast", function() {
        });
    });
    $("#departmentLinks li a").mouseout(function() {
        $(this).animate({ "opacity": "1.0" }, 10, function() {
        });
    });
	
	$("#mhProducts li.mhProduct ").mouseover(function() {
        $(this).animate({ "opacity": "0.4" }, "fast", function() {
        });
    });
    $("#mhProducts li.mhProduct ").mouseout(function() {
        $(this).animate({ "opacity": "1.0" }, 10, function() {
        });
    });


    imageFlip = 0;
    // insert first image into item_2. Then manipulate from there.

    release = 1; // if release is set to 1, we execute the next or back functions, if not we wait until animation has completed.

    // enter the location for each image in the appropriate section below. You do NOT need to include image locations as this will be done automatically
    // by it using the imagePath variable and appending a number to it.

    theURL = location.href.toLowerCase();



    if (theURL.indexOf("default.aspx") > 0 && theURL.indexOf("lifestyle") < 0 && theURL.indexOf("store") < 0) {
        // if URL is home
        numSwitches = 1 // please place the total number of image switch things in this variable.

        switchImageHref = {
            "switchImg_0": ["/Almanac.aspx"]
        }

        switchImageImg = {
            "switchImg_0": "../Images/global/xmas09/home_landing_"
        }

        imageFlip = 1;

    }

    if (theURL.indexOf("id=womens") > 0) {
        // if URL is womenswear.
        numSwitches = 1 // please place the total number of image switch things in this variable.

        switchImageHref = {
            "switchImg_0": ["/Store/ProductDetails.aspx?ProductRef=003420&Option=003420003"]
        }

        switchImageImg = {
            "switchImg_0": "../Images/global/xmas09/womens_landing_"
        }

        imageFlip = 1;
    }

    if (theURL.indexOf("id=mens") > 0) {
        // if URL is menswear.
        numSwitches = 1 // please place the total number of image switch things in this variable.

        switchImageHref = {
            "switchImg_0": ["/Store/ProductDetails.aspx?ProductRef=002873&Option=002873677"]
        }

        switchImageImg = {
            "switchImg_0": "../Images/global/xmas09/mens_landing_"
        }
        //alert(counter);
        imageFlip = 1;

    }

    if (theURL.indexOf("id=homewares") > 0) {
        // if URL is homewares.
        numSwitches = 1 // please place the total number of image switch things in this variable.

        switchImageHref = {
            "switchImg_0": ["/Store/ProductDetails.aspx?ProductRef=003427&Option=003427681"]
        }

        switchImageImg = {
            "switchImg_0": "../Images/global/xmas09/homewares_landing_"
        }
        return false;
        imageFlip = 1;
    }

    if (theURL.indexOf("/lifestyle/default.aspx") > 0) {
        // if URL is homewares.


        numSwitches = 1 // please place the total number of image switch things in this variable.

        switchImageHref = {
            "switchImg_0": ["#"]
        }

        switchImageImg = {
            "switchImg_0": "../Images/global/Spring10/community_landing_"
        }

        imageFlip = 1;

    }

    if (theURL.indexOf("/whatson/photography.aspx") > 0) {
        // if URL is photography
        numSwitches = 4 // please place the total number of image switch things in this variable.

        switchImageHref = {
            "switchImg_0": ["#", "#"],
            "switchImg_1": ["#", "#"],
            "switchImg_2": ["#", "#"],
            "switchImg_3": ["#", "#"]
        }

        switchImageImg = {
            "switchImg_0": "../../Images/whatsOn/Photography/polly",
            "switchImg_1": "../../Images/whatsOn/Photography/eleanor",
            "switchImg_2": "../../Images/whatsOn/Photography/taraDarby",
            "switchImg_3": "../../Images/whatsOn/Photography/drewReynolds"

        }
			
        imageFlip = 1;
	
    }

    if (theURL.indexOf("/whatson/art.aspx") > 0) {
        // if URL is photography
        numSwitches = 2 // please place the total number of image switch things in this variable.

        switchImageHref = {
            "switchImg_0": ["#", "#"],
            "switchImg_1": ["#", "#"]
        }

        switchImageImg = {
            "switchImg_0": "../../Images/whatsOn/Art/yvonne",
            "switchImg_1": "../../Images/whatsOn/Art/quentin"
        }

        imageFlip = 1;
    }


    if (theURL.indexOf("/whatson/poetry.aspx") > 0) {
        // if URL is photography
        numSwitches = 1 // please place the total number of image switch things in this variable.

        switchImageHref = {
            "switchImg_0": ["#", "#", "#"]
        }

        switchImageImg = {
            "switchImg_0": "../../Images/whatsOn/poetry/luke"
        }

        imageFlip = 1;
    }

    if (imageFlip == 1) {

        counterHold = new Array();
        for (i = 0; i < numSwitches; i++) {


            abc = "";
            //numberImages = $(".hideContent ul > li").size();
            buildPath = eval("switchImageHref.switchImg_" + i + ".length");
            numberImages = buildPath;
            //console.log(numberImages);

            //alert("asdfasdf" + numberImages);

            randomnumber = Math.floor(Math.random() * (numberImages - 1));

            nr = randomnumber + 1;
            if (nr < 10) { newrand = "0" + nr }
            else { newrand = nr; }


            imagePath = eval("switchImageImg.switchImg_" + i);
            imagePathHref = eval("switchImageHref.switchImg_" + i);



            if (imagePathHref[randomnumber] == "#") {
                abc = "<img src='" + imagePath + newrand + ".jpg'>";
            }
            else {
                abc = "<a href='" + imagePathHref[randomnumber] + "'><img src='" + imagePath + newrand + ".jpg'></a>";
            }



            index = i;
            $(".itemShow:eq(" + index + ")").html(abc);
            counter = randomnumber;
            counterHold.push(randomnumber);
            //alert(counter);
            //end for loop
        }



        $(".next").click(function() {
            index = $(".next").index(this);

            if (release == 1) {
                // check to see if its the last element in the array. If it is, we need to go back to number 0 in the array.
                var quickadd = counterHold[index] + 1;
                counterHold[index] = quickadd;

                if (counterHold[index] == numberImages) { counterHold[index] = 0; } // return counter back to the start

                // now display the next image into item_3.


                release = 0;
                //alert(counter);

                counter2 = counterHold[index] + 1;
                //alert($(".itemShow:eq(" + index + ")").html());
                $(".itemShow:eq(" + index + ")").animate({ "opacity": "0.0" }, "slow", function() {
                    // now we are done, replace item_2 with the content of item_3 and move the scoller back to its position.



                    if (counter2 < 10) { newrand = "0" + counter2 }
                    else { newrand = counter2; }

                    imagePath = eval("switchImageImg.switchImg_" + index);
                    imagePathHref = eval("switchImageHref.switchImg_" + index);




                    if (imagePathHref[counter] == "#") {
                        abcd = "<img src='" + imagePath + newrand + ".jpg'>";
                    }
                    else {
                        abcd = "<a href='" + imagePathHref[counter] + "'><img src='" + imagePath + newrand + ".jpg'></a>";

                    }




                    $(".itemShow:eq(" + index + ")").html(abcd);

                    $(".itemShow:eq(" + index + ")").animate({ "opacity": "1.0" }, "slow", function() {
                        release = 1;
                    });

                });

            }
            return false;
        });

        $(".back").click(function() {

            index = $(".back").index(this);

            if (release == 1) {
                // check to see if its the last element in the array. If it is, we need to go back to number 0 in the array.

                var quickadd = counterHold[index] - 1;
                counterHold[index] = quickadd;
                if (counterHold[index] == -1) { counterHold[index] = (numberImages - 1); } // return counter back to the start



                release = 0;

                $(".itemShow:eq(" + index + ")").animate({ "opacity": "0.0" }, "slow", function() {

                    counter2 = counterHold[index] + 1;
                    if (counter2 < 10) { newrand = "0" + counter2 }
                    else { newrand = counter2; }

                    imagePath = eval("switchImageImg.switchImg_" + index);
                    imagePathHref = eval("switchImageHref.switchImg_" + index);



                    if (imagePathHref[counter] == "#") {
                        abcd = "<img src='" + imagePath + newrand + ".jpg'>";
                    }
                    else {

                        abcd = "<a href='" + imagePathHref[counter] + "'><img src='" + imagePath + newrand + ".jpg'></a>";
                    }






                    $(".itemShow:eq(" + index + ")").html(abcd);

                    $(".itemShow:eq(" + index + ")").animate({ "opacity": "1.0" }, "slow", function() {
                        release = 1;
                    });

                });
            }
            return false;
        });

    } //end test for imageFlip.
	
	
		
		
});