$(document).ready(function(){
   
   $(function() {
	// Use this example, or...
	$('a[@rel*=lightbox]').lightBox(); // Select all links that contains lightbox in the attribute rel
});

   
    //imageSwitch on productList
    $("img.variantListImage").click(function () {
    info = this.id.split(";")
    productImg = document.getElementById(info[0])
    $("img#"+info[0]).fadeOut("slow")
    setTimeout(function() { productImg.src=info[1] }, 600);
    $("img#"+info[0]).fadeIn("slow")
    link = document.getElementById("link;"+info[0])
    if (link.href.indexOf("&var") == -1) {
    link.href=link.href+"&var="+info[2]
    }else{
    link.href= link.href.slice(0,link.href.indexOf("&var"))  +"&var="+info[2]
    }
    
    });
    

    
});


function changeClass(name, name2, name3){
    thediv = document.getElementById(name)
    thediv2 = document.getElementById(name2)
    thediv3 = document.getElementById(name3)
    if(thediv.className == 'Selected' || thediv.className == 'Selected female'){
        thediv.className= thediv.className.replace('Selected','notSelected')
    } else if (thediv.className == 'notSelected' || thediv.className == 'notSelected female'){
        thediv.className = thediv.className.replace('notSelected','Selected')
        if(thediv2.className == 'Selected' || thediv2.className == 'Selected female'){
            thediv2.className = thediv2.className.replace('Selected','notSelected')
        }
        if(thediv3.className == 'Selected' || thediv3.className == 'Selected female'){
            thediv3.className = thediv3.className.replace('Selected','notSelected')
        }
    }
}
function initMenus() {
	$('ul.menu ul').hide();
	$.each($('ul.menu'), function(){
		$('#' + this.id + ' ul.expanded').show();
	});
	$('ul.menu li div').click(
		function() {
			var checkElement = $(this).next();
			var parent = this.parentNode.parentNode.id;

			if($('#' + parent).hasClass('noaccordion')) {
				$(this).next().slideToggle('normal');
				
				return false;
			}
			if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
				if($('#' + parent).hasClass('collapsible')) {
					$('#' + parent + ' ul:visible').animate
                    ({
                    
                    opacity: "hide",
                     height: "hide"
                    }, 500);
                   $('#' + parent + ' ul:visible').slideUp('normal');
				}
				return false;
			}
			if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
				$('#' + parent + ' ul:visible').animate
                    ({
                    height: "hide",
                    opacity: "hide"
                    }, 500);
                      
                checkElement.animate
                ({
                height: "show",
                opacity: "show"
                
                }, 500);
                liArray = document.getElementById(parent).childNodes;
                      i=0;
                      while(liArray[i]){
                      if (liArray[i].firstChild.firstChild.className == "arrowSub left" && liArray[i].firstChild!= this){
//                        alert(liArray[i].firstChild.id)
                        changeArrow(liArray[i].firstChild)
                        }
                        i++;
                      }
				return false;
				
			}
		}
	);
}
$(document).ready(function() {initMenus();});

//function changeArrow(myItem){

//var id = myItem.id;
//var theArrow = document.getElementById("arrowSub"+id);   
//if (theArrow.height == "" || theArrow.height == "7"){
//    isRight = true
//}else
//    isRight = false

//var angle=0;
//setInterval ( function (e) {
//    rotate();
//}, 1 );
//function rotate() {
//    if (angle < 90){
//        angle=angle+9;
//        if (isRight == true)
//            $('#'+theArrow.id).rotateRight(9);
//        else
//            $('#'+theArrow.id).rotateLeft(9);
//    }
//}

function changeArrow(myItem){

    var id = myItem.id;
    var theArrow = document.getElementById("arrowSub"+id);   
    if (myItem.firstChild.className == "arrowSub right"){
        isRight = true;
    }else{
        isRight = false;
    }
    if (myItem.firstChild.className == "arrowSub right"){
        myItem.firstChild.className="arrowSub left";
    }else{
        myItem.firstChild.className="arrowSub right";
    }
    var angle=0;
    if (isRight == true){
        $('#'+theArrow.id).rotateRight(90);
            }else{
            $('#'+theArrow.id).rotateLeft(90);
            }
//    setInterval ( function (e) {
//        rotate();
//    }, 1 );
//    function rotate() {
//        if (angle < 90){
//            angle=angle+9;
//            if (isRight == true){
//                $('#'+theArrow.id).rotateRight(9);
//            }else{
//            $('#'+theArrow.id).rotateLeft(9);
//            }
//        }

//    }
}


//$('#arrowSub31').rotateRight(90);

//    selected ="/images/default/icon_arrow_down.gif";
//    notSelected ="/images/default/icon_arrow_right.gif";
//    var id = myItem.id;
//    var theArrow = document.getElementById("arrowSub"+id);
//    if (theArrow.src == selected){
//        theArrow.src = notSelected;
//    }else{
//        theArrow.src = selected;
//    }
