

/* properties */
var stat = true;
var stat2 = true;
var statemail = true;
var LOCAL

/* function */
function setLocal(str){
    LOCAL = str;
}

function check(){
    if(stat){
        document.getElementById("mailinglist").value = "";
        document.getElementById("mailinglist").style.color = "#000";
        stat = false;
    }
}

function checkdefvalue(){
    if (document.getElementById("mailinglist") != null){
        var defval = document.getElementById("mailinglist").value;
        if(defval != "JOIN OUR MAILING LIST" || defval == ""){
            defval = "JOIN OUR MAILING LIST";
        }
    }
}

function checkdefsearchvalue(){
    var defval2 = document.getElementById("s").value;

    if(defval2 != "SEARCH" || defval2 == ""){
        defval2 = "SEARCH";
    }
}

function checksearch(){
    if(stat2){
        document.getElementById("s").value = "";
        document.getElementById("s").style.color = "#000";
        stat2 = false;
    }
}

function isValidEmail(str) {
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

function checkemail(){
    var mailinglist = document.getElementById("mailinglist").value;

    if(!isValidEmail(mailinglist) || mailinglist == ""){
        statemail = false;
        document.getElementById("mailinglist").value = "";
        alert("Error. An invalid email address has been entered.");
    }
    return statemail;
}

function getMonth(val) {
    var monthArray = new Array("JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE","JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER");
    for (var i=1; i<=monthArray.length; i++) {
        if (i == val) {
            return monthArray[i-1];
        }
    }
    return(-1);
}

/* on initialization */
$(document).ready(function(){
//(function($){

    /*** header ***/
    var i = 0;
    $(".menu-header ul.menu").children().each(function(){
        if(i == 6){
            $(this).after('<li class="search">'+$(".search-hidden").html()+'</li>');
            $("#s").attr("value", "SEARCH");
            $("#s").attr("size", "20");
            $("#s").click(function(){
                checksearch();
            });
            //$(this).after('<li><input type="text" name="search" id="searchmenu" value="SEARCH" onclick="checksearch();" /></li>');
        }
        i++;
    });
    checkdefsearchvalue();

    /* home page */
    var parent = document.getElementById("yesteryear-content");

    // if on HOME PAGE
    if (parent != null){
        // animation
        $(".news-main-content").hover(
            function(){
                $('#thumbnail-image').animate({top: 270}, 300);
				$('#bigimg').animate({height: 621, width: 621, marginLeft: 0}, 300);
            },
            function(){
                $('#thumbnail-image').animate({top: 360}, 300);
				$('#bigimg').animate({height: 711, width: 711, marginLeft: -45}, 300);
            }
        );

        $(".smallimg").hover(
            function(){
				var src = $(this).attr("src");
				$('#bigimg').delay(600).queue(function(next) { $(this).attr("src", src); next(); });
            },
            function(){
            }
        );

        $(".shop-main-content").hover(
            function(){
                $(".shop-main-content img").animate({opacity: 0.25});
                $(".shop-main-content img").animate({filter:alpha(opacity=25)});
            },
            function(){
                $(".shop-main-content img").animate({opacity: 100});
                $(".shop-main-content img").animate({filter:alpha(opacity=100)});
            }
        );

        $("#artist").hover(
            function(){
                $("#artist a img").animate({opacity: 0.25});
                $("#artist a img").animate({filter:alpha(opacity=25)});
            },
            function(){
                $("#artist a img").animate({opacity: 100});
                $("#artist a img").animate({filter:alpha(opacity=100)});
            }
        );

        $("#merchant").hover(
            function(){
                $("#merchant a img").animate({opacity: 0.25});
                $("#merchant a img").animate({filter:alpha(opacity=25)});
            },
            function(){
                $("#merchant a img").animate({opacity: 100});
                $("#merchant a img").animate({filter:alpha(opacity=100)});
            }
        );

        $("#who").hover(
            function(){
                $("#who a img").animate({opacity: 0.25});
                $("#who a img").animate({filter:alpha(opacity=25)});
            },
            function(){
                $("#who a img").animate({opacity: 100});
                $("#who a img").animate({filter:alpha(opacity=100)});
            }
        );

        /* create effect kwicks */
        var sum = parent.getElementsByTagName("li").length;
        $('.kwicks').kwicks({
            max : 127,
            duration: 150,
            spacing : 8,
            sticky : true,
            defaultKwick: sum-1
        }).each(function(){
			$(this).children().click(function(event){
				var id = $(this).children().attr("id");
				window.location.href = LOCAL + "/discography/?id=" + id;
			})
        });

        /* create effect carousel */
        /*$("#slider_carousel").bxSlider({
            auto: true,
            pause: 3000,
            speed: 200,
            infiniteLoop: true
        }).click(function(){
             window.location.href = LOCAL + "/category/featured/";
        });*/
        
        $('#slider_carousel').anythingSlider({
//            startStopped    : true, // If autoPlay is on, this can force it to start stopped
            width           : 287,   // Override the default CSS width
            height          : 156,
            theme           : 'minimalist-round',
            //easing          : 'easeInOutBack',
//            autoPlay        : true,
            autoPlayLocked  : true,  // If true, user changing slides will not stop the slideshow
            pauseOnHover    : true,
//            resumeDelay     : 1000, // Resume slideshow after user interaction, only if autoplayLocked is true (in milliseconds).
            onSlideComplete : function(slider){
                // alert('Welcome to Slide #' + slider.currentPage);
            },
//            stopAtEnd : false,
            onShowStop : function(e, slider){
//                setTimeout(function(){
//                    if (slider.currentPage === slider.pages) { slider.gotoPage(1); }
//                }, 5000);
            }
        });

        $('a').focus(function(){
             $(this).blur();
        });
		
		$("#slider_carousel li a").each(function(){
			$(this).hover(
				function(){
					$(this).children("img").animate({opacity: 0.25});
                	$(this).children("img").animate({filter:alpha(opacity=25)});
				},
				function(){
					$(this).children("img").animate({opacity: 100});
               		$(this).children("img").animate({filter:alpha(opacity=100)});
				}
			);
		});
    }
	else{
		$(".shop").hover(
            function(){
                $(".shop img").animate({opacity: 0.75});
                $(".shop img").animate({filter:alpha(opacity=75)});
            },
            function(){
                $(".shop img").animate({opacity: 100});
                $(".shop img").animate({filter:alpha(opacity=100)});
            }
        );
		
		$(".left-image").hover(
            function(){
                $(".left-image img").css({opacity: 0.75});
                $(".left-image img").css({filter:alpha(opacity=75)});
            },
            function(){
                $(".left-image img").css({opacity: 100});
                $(".left-image img").css({filter:alpha(opacity=100)});
            }
        );
	}

    // event page
    if ($(".calendar-tab").html() != null){
        $(".calendar-tab").children().each(function(){
            $(this).children().bind('click', function(){
                var eventdate = $(this).find('span.calnk').find('span.event-dat').html();
                var eventimage = $(this).find('span.calnk').find('span.event-image').html();
				var eventdesc = "";
				for(var i=0;i<$(this).find('span.calnk').find('span.event-desc').size();i++){
					eventdesc += "<b>"+$(this).find('span.calnk').find('span.event-title').eq(i).html()+"</b><br />"+$(this).find('span.calnk').find('span.event-desc').eq(i).html()+"<br /><br />";
				}
				
				if(eventdate != null){
					var da = eventdate.split(" ");
					var dat = da[1].split("-");
					var newdate = da[0]+" "+dat[2]+" "+getMonth(parseInt(dat[1]))+" "+dat[0];
					$(".events-details-date").html(newdate);
				}
				else{
					$(".events-details-date").html("");
				}
				
				if(eventimage != "" || eventimage != null){
					$(".events-details-content").html('<img src="'+eventimage+'" />');
				}
				else{
					$(".events-details-content").html('<img src="" />');
				}
    
				$(".event-description").html(eventdesc);
            });
        });
    }

    // on EVERY PAGE
    if (document.getElementById("left-brand-ul") != null){
        $('.kwicksvertical').kwicks({
            isVertical: true,
            max : 136,
            duration: 150,
            spacing : 8
        }).each(function(){
			$(this).children().click(function(event){
				var id = $(this).children().attr("id");
				window.location.href = LOCAL + "/discography/?id=" + id;
			})
        });
    }
});
//})(jQuery);
