var pressFormShow = 0;

$(document).ready(function()
{
	
	$("a[href^='http://']").click(
		function(){
			if (this.host.indexOf(window.location.hostname) == -1){
				$(this).attr("target","_blank");
			}
		}
	);
	
	$(".mobMain").each(function(){
		$(this).width(screen.width);
	});
	
	
    $(".mainNav a").mouseover(function(){
       $(this).parent().addClass("hover"); 
    }).mouseout(function(){
        $(this).parent().removeClass("hover");
    });
    
    $(".menu a").mouseover(function(){
        $(this).animate({ paddingLeft: '5px'}, 100, 'easeOutCubic');
    }).mouseout(function(){
        $(this).animate({ paddingLeft: '0px'}, 100, 'easeOutCubic');
    });
    
    $(".jqPressForm").click(function() {
        if (pressFormShow == 0)
        {
            $(".jqPressFormContainer:hidden").each(function()
            {
                $(this).fadeIn(500);
                pressFormShow = 1;
                $(".container").animate({ paddingBottom: '210px'}, 100, 'easeOutCubic');  
            });
        }
        else
        {
            $(".jqPressFormContainer:not(:hidden)").each(function()
            {
                $(this).fadeOut(500);
                pressFormShow = 0;
                $(".container").animate({ paddingBottom: '210px'}, 100, 'easeOutCubic');  
            }); 
        }  
    });
    
    $(".jqCheckbox").click(function(){
        if (this.tagName.toLowerCase() == "input")
        {
            if (this.checked)
            {
                $(this).next().addClass("active");
            }
            else
            {
                $(this).next().removeClass("active");
            }
        }
        var artists = "";   
        $(".jqCheckbox").each(function(){
        if (this.tagName.toLowerCase() == "input")
        {
            if (this.checked)
            {
                $(this).next().addClass("active");
                artists += $(this).val() + ",";
            }
            else
            {
                $(this).next().removeClass("active");
            }
        }
        $(".jqCheckboxVal").val(artists.substring(0,artists.length - 1));
        });
    });
    
    var artists = "";   
    $(".jqCheckbox").each(function(){
        if (this.tagName.toLowerCase() == "input")
        {
            if (this.checked)
            {
                $(this).next().addClass("active");
                artists += $(this).val() + ",";
            }
            else
            {
                $(this).next().removeClass("active");
            }
        }
        $(".jqCheckboxVal").val(artists.substring(0,artists.length - 1));
        
    });
    
    $(".jqDateMM, .jqDateYY, .jqDateDD").change(function(){
        $(".jqDate").val($(".jqDateYY").val() + $(".jqDateMM").val() + $(".jqDateDD").val());
    });
    

    $(".jqValidateForm").click(function(){
        var form = $(this).parent().parent().parent();
        var fields = $(".jqValidateFields").val().split(",");
        var err = ""; count = 0;
        
        for (var i in fields)
        {
            var obj = $("#" + fields[i]);
            if ((obj.val() == "") || (obj.val() == obj.attr("title")))
            {
                if (!count == 0) { err +=  ", "; }
                err += (obj.attr("title") != undefined && obj.attr("title") != "") ? obj.attr("title") : obj.attr("name");
                obj.addClass("notvalid");
                count++;
                
                $(obj).not("select").bind("keyup click", function(){
                    if(!(($(this).val() == "") || ($(this).val() == $(this).attr("title"))))
                    { 
                        $(this).removeClass("notvalid");
                    }
                    else 
                    {
                        $(this).addClass("notvalid");
                    }
                });
                $(obj).not("input").not("textarea").bind("change keyup", function(){
                    if(!(($(this).val() == "") || ($(this).val() == $(this).attr("title"))))
                    { 
                        $(this).removeClass("notvalid");
                    }
                    else 
                    {
                        $(this).addClass("notvalid");
                    }
                });
            }
            else
            {
                obj.removeClass("notvalid");
            }
        }
        if (err != "")
        {
            return false;
        }
        else
        {
            form.submit();
        }
        
    });
    
    $(".jqToggle").focus(function(){
        if ($(this).val() == $(this).attr("title"))
        {
            $(this).val("");
        }
    }).blur(function(){
        if ($(this).val() == "")
        {
            $(this).val($(this).attr("title"));
        }
    });
    
    $(".jqSubmitPresskit").click(function(){
        var artist = $(".jqArtist").val();
        var email = $(".jqEmail").val();
        $("#formPresskit").html("<img src='/img/loader.gif' />");
        $.ajax({
            type: "GET",
            url: "/",
            cache: false,
            data: { id: 21, artist: artist, email: email, a: "presskit" },
            async: true,
            success: function(result) 
            {
                $("#formPresskit").html(result);
            }
        });
    });

     $(".jqSubmitNewsletter").click(function(){
        var frmname = $(".jqName").val();
        var frmemail = $(".jqEmail").val();
        var frmlists = $(".jqCheckboxVal").val();
        
        var form = $(this).parent().parent().parent();
        var fields = $(".jqValidateFields").val().split(",");
        var err = ""; count = 0;
        
        for (var i in fields)
        {
            var obj = $("#" + fields[i]);
            if ((obj.val() == "") || (obj.val() == obj.attr("title")))
            {
                if (!count == 0) { err +=  ", "; }
                err += (obj.attr("title") != undefined && obj.attr("title") != "") ? obj.attr("title") : obj.attr("name");
                obj.addClass("notvalid");
                count++;
                
                $(obj).not("select").bind("keyup click", function(){
                    if(!(($(this).val() == "") || ($(this).val() == $(this).attr("title"))))
                    { 
                        $(this).removeClass("notvalid");
                    }
                    else 
                    {
                        $(this).addClass("notvalid");
                    }
                });
                $(obj).not("input").not("textarea").bind("change keyup", function(){
                    if(!(($(this).val() == "") || ($(this).val() == $(this).attr("title"))))
                    { 
                        $(this).removeClass("notvalid");
                    }
                    else 
                    {
                        $(this).addClass("notvalid");
                    }
                });
            }
            else
            {
                obj.removeClass("notvalid");
            }
        }
        if (err != "")
        {
            return false;
        }
        else
        {
			$("#formNewsletter").html("<img src='/img/loader.gif' />");
		    $.ajax({
		        type: "POST",
		        url: "/",
		        cache: false,
		        data: { id:1, a:'newsletter', name: frmname, email: frmemail, lists: frmlists },
		        async: true,
		        success: function(result) 
		        {
		            $("#formNewsletter").html(result);
		        }
		    });
        }
        
    });
    
    //alert(document.frames["newsletterframe"].document.body.scrollHeight);
    
    $(".jqVideo").click(function() {
        var code = $(this).attr("data-code");
        var player = "<iframe width=\"721\" class=\"youtube\" height=\"431\" src=\"http://www.youtube.com/embed/" + code + "\" frameborder=\"0\" allowfullscreen></iframe>"; 
        //console.log(player) ;
        //$("div.video").html(player);
        $("#youtube").attr("src", "http://www.youtube.com/embed/" + code);
    });

});

function handleEnter (field, event) 
{
	if (window.event.keyCode == 13) window.event.keyCode = 0; 
}      
 
 function doIframe(){
	o = document.getElementsByTagName('iframe');
	for(i=0;i<o.length;i++){
		if (/\bautoHeight\b/.test(o[i].className)){
			setHeight(o[i]);
			addEvent(o[i],'load', doIframe);
		}
	} 
    
}

function setHeight(e){
	if(e.contentDocument){
		e.height = e.contentDocument.body.offsetHeight + 35;
	} else {
		e.height = e.contentWindow.document.body.scrollHeight;
	}
}

function addEvent(obj, evType, fn){
	if(obj.addEventListener)
	{
	obj.addEventListener(evType, fn,false);
	return true;
	} else if (obj.attachEvent){
	var r = obj.attachEvent("on"+evType, fn);
	return r;
	} else {
	return false;
	}
}

if (document.getElementById && document.createTextNode)
{
 addEvent(window,'load', doIframe);	
}

