/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

jQuery.noConflict();
        var $j = jQuery;

    $j("#left").corner("10px");
    $j("#right").corner("10px");
    $j("#middle").corner("10px");
    $j(".advancedSearch").corner("10px");
    $j("#centered").corner("10px");
    $j("#containercd ul").corner("10px");
    $j(".topInfo").corner("10px");
    $j(".LeftInfoMI").corner("10px");
    $j(".RightInfoMI").corner("10px");
    $j(".left").corner("10px");
    $j(".leftScreens").corner("10px");
    $j(".right").corner("10px");
    $j(".header").corner("top");
    $j("#leftadvance").corner("10px");
    $j("#bootlegTable").corner("bottom");
    $j("#middleVideos").corner("10px");
    $j("#leftItem").corner("10px");
    $j("#innerMenu li").corner("top");

$j(function(){

   $j(".url").click(function(){

       var url = $j(this).attr("url");
       url = (url != "coverart") ? "?route=" + url : url+"/";

       window.location.replace(url);

   })

});

$j(function(){

   var emailSubmit = $j("#emailSubmit");

   emailSubmit.click(function(){

      var from = $j("#from");
      var email = $j("#e-mail");
      var subject = $j("#subject");
      var message = $j("#message");
      var agree = document.getElementById("agree");

      if(from.val() == ""){
          alert("Field 'From' is required");
          from.focus();
          return false;
      }
      if(email.val() == ""){

          alert("Field 'E-mail' is required");
          email.focus();
          return false;

      }
      else{

          var emailCheck = email.val();
          if(emailCheck.indexOf("@") == -1){
              alert("You entered a not valid e-mail address, please try again");
              email.focus();
              return false;
          }

      }
      if(subject.val() == ""){

          alert("Field 'Subject' is required");
          subject.focus();
          return false;

      }
      if(message.val() == ""){

          alert("Field 'Message' is required");
          message.focus();
          return false;

      }

      if(agree.checked != true){

          alert("You must agree to my trading rules, if you didn't read them go on and do it.");
          return false;

      }
      
      $j("#emailForm").submit();
      

   });


});

function submitForm(){
	document.getElementById("styleform").submit();
}


//$j(document).ready(function() {
//    var songList = $j("input#songlist");
//
//    if(songList.length > 0){
//
//        $j.ajax({
//            type: "POST",
//            url: "model/sendData.php?section=song",
//            dataType: "JSON",
//            cache: false,
//            error: function(){
//                alert("Error");
//                },
//              success: function(strData){
//
//                songList.autocomplete({
//                    source: [strData]
//                });
//
//              }
//
//        });
//
//    }
//
//});

$j(document).ready(function() {
    var songList = $j("input#songlist");

    if(songList.length > 0){

        songList.autocomplete("model/sendData.php" ,{
                   matchContains: true,
                   selectFirst: false,
                   sec: "song"
                });
    }

});

$j(function(){

    var search = $j("#search");

    search.click(function(){

        var tour = $j("#tour");
        var year = $j("#year");
        var month = $j("#month");
        var country = $j("#country");
        var city = $j("#city");
        var source = $j("#source");
        var song = $j("#songlist");
        var audio = $j(this).attr("is");
        
        var type = (audio == "") ? 1 : 2;

        var jContainer = $j("#showBootlegs");

        var aData = "year=" + year.val() + "&month=" + month.val() + "&country=" + country.val() +
                    "&city=" + city.val() + "&source=" + source.val() + "&song=" + song.val() +
                    "&tour=" + tour.val() +"&audio=" + audio + "&type="+ type +
                    "&section=bootlegs";


        $j.ajax({
            type: "POST",
            url: "model/sendData.php",
            data: aData,
            cache: false,
            error: function(){
                alert("Error");
                },
                beforeSend: function(){
                    jContainer.html("<img src='img/loading.gif' style='margin-top:30px;'/><br/><span class='highlight'>Loading...</span>");
                },
              success: function(strData){

                    jContainer.html(strData);
                    resetFields();
                    song.val("");
                    source.val("");
                    tour.val("");

              }

        });

    });

});

$j(function(){

   $j("#tour").change(function(){

       var audio = $j("#search").attr("is");
       var type = (audio == "") ? 1 : 2;
       var tour = $j(this).val();
       var section = "all";
       if(tour != ""){
           section = "year";
       }

       var aData = "tour=" + tour + "&type=" + type + "&section=" + section;

       $j.ajax({
            type: "POST",
            url: "model/sendData.php",
            data: aData,
            cache: false,
            error: function(){
                alert("Error");
                },
              success: function(strData){

                var response = strData.split("*");
                $j("td.month").html(response[1]);
                $j("td.country").html(response[2]);
                $j("td.year").html(response[0]);

              }

        });
   })
});

$j(function(){

   $j("#year").change(function(){

       var audio = $j("#search").attr("is");
       var type = (audio == "") ? 1 : 2;
       var year = $j(this).val();
       var tour = $j("#tour");
       var section = "all";
       if(year != ""){
           section = "month";
       }

       var aData = "year=" + year + "&type=" + type + "&tour=" + tour.val() + "&section="+section;

       $j.ajax({
            type: "POST",
            url: "model/sendData.php",
            data: aData,
            cache: false,
            error: function(){
                alert("Error");
                },
              success: function(strData){

                var response = strData.split("*");
                $j("td.month").html(response[0]);
                $j("td.country").html(response[1]);


              }

        });
   })
});

$j(function(){

   $j("#month").live("change",function(){

       var audio = $j("#search").attr("is");
       var type = (audio == "") ? 1 : 2;
       var month = $j(this).val();
       var year = $j("#year").val();
       var tour = $j("#tour");

       var aData = "year=" + year + "&type=" + type + "&month=" + month + "&tour=" + tour.val() + "&section=country";

       $j.ajax({
            type: "POST",
            url: "model/sendData.php",
            data: aData,
            cache: false,
            error: function(){
                alert("Error");
                },
              success: function(strData){
                $j("td.country").html(strData);

              }

        });
   })
});

$j(function(){

   $j("#country").live("change",function(){

       var country = $j("#country").val();

       var aData = "country=" + country +  "&section=city";

       $j.ajax({
            type: "POST",
            url: "model/sendData.php",
            data: aData,
            cache: false,
            error: function(){
                alert("Error");
                },
              success: function(strData){
                $j("td.city").html(strData);

              }

        });
   })
});

function resetFields(){

       var section = "all";
       var audio = $j("#search").attr("is");
       var type = (audio == "") ? 1 : 2;
       
       var aData = "type=" + type + "&section="+section;

       $j.ajax({
            type: "POST",
            url: "model/sendData.php",
            data: aData,
            cache: false,
            error: function(){
                alert("Error");
                },
              success: function(strData){

                var response = strData.split("*");
                $j("td.year").html(response[0])
                $j("td.month").html(response[1]);
                $j("td.country").html(response[2]);
                $j("#city").html("<option class='fOp' value=''>Select City</option>");

              }

        });

}

$j(function(){

   $j("#lineup li").live("click",function(){

        var lineup = $j(this).attr("reg");
        var jContainer = $j("#pictures");

        var aData = "lineup=" + lineup + "&section=lineup";

        $j.ajax({
            type: "POST",
            url: "model/sendData.php",
            data: aData,
            cache: false,
            error: function(){
                alert("Error");
                },
              success: function(strData){

                jContainer.hide().html("<br/>"+strData).fadeIn("slow");

              }

        });


   });
   
});

$j(function(){

   $j("#item li").live("click",function(){

        var item = $j(this).attr("reg");
        var jContainer = $j("#itemDescription");

        var aData = "item=" + item + "&section=item";

        $j.ajax({
            type: "POST",
            url: "model/sendData.php",
            data: aData,
            cache: false,
            error: function(){
                alert("Error");
                },
                beforeSend: function(){
                    jContainer.html("<center><img src='img/loading.gif' style='margin-top:30px; border:0px'/><br/><span class='highlight'>Loading...</span></center>");
                },
              success: function(strData){

                jContainer.hide().html(strData).fadeIn("slow");

              }

        });


   });

});


$j(function() {

    var lineupCar = $j(".bandLineup");

    if(lineupCar.length > 0){

        lineupCar.jCarouselLite({
            btnNext: ".next",
            btnPrev: ".prev",
            speed: 1000,
            visible: 4,
            start: 0,
            auto: 0
        });

    }
    
});


$j(function(){

    $j("#innerMenu li").click(function(){

        var cat = $j(this).attr("reg");
        var dir = $j(this).attr("class");
        var jContainer = $j("#itemList");
        var aData = "category=" + cat + "&section=itemList";
        var title = $j(this).text();
        
        for(var i=1; i<11; i++){

            if(i == cat){
                
                $j("#innerMenu li").css("background","url(img/dashtdback.jpg) #000000 center repeat-x");
                $j(this).css("background", "url("+ dir + "/img/dashtdbackSelected.jpg) #000000 center repeat-x");
            }


        }

        $j.ajax({
            type: "POST",
            url: "model/sendData.php",
            data: aData,
            cache: false,
            error: function(){
                alert("Error");
                },
            beforeSend: function(){
              jContainer.html("<img src='img/loading.gif' style='margin-top:30px;'/><br/><span class='highlight'>Loading...</span>");
            },
              success: function(strData){

                $j.getScript("/js/itemcarousel.js");
                $j(".itemTitles").html(title);
                jContainer.hide().html(strData).fadeIn("slow");

              }

        });

    });

});


$j(function(){

   $j("#videolist li").live("click", function(){

        $j( 'html, body' ).animate( { scrollTop: 0 }, "slow" );
        var videoId = $j(this).attr("reg");

        var aData = "video_id="+videoId+"&section=videos";

        var jVideoContainer = $j("#videoContainer");
        var jVideoInfoContainer = $j("#videoInfoContainer");

        $j.ajax({
            type: "POST",
            url: "model/sendData.php",
            data: aData,
            cache: false,
            error: function(){
                alert("Error");
                },
            beforeSend: function(){
              jVideoContainer.html("<img src='img/loading.gif' style='margin-top:30px;'/><br/><span class='highlight'>Loading...</span>");
            },
              success: function(strData){

                    var data = strData.split("#$#");
                    jVideoContainer.html(data[0]);
                    jVideoInfoContainer.html(data[1]);


              }

        });

   });

});

$j(function(){

   $j("#searchvideo").click(function(){

      $j(this).select();

   });

   $j("#searchvideo").keyup(function(){

        var search = $j("#searchvideo").val();

        var aData = "search="+search+"&section=videoList";

        var jContainer = $j("#videoList");

        if(search.length > 3){

            $j.ajax({
                type: "POST",
                url: "model/sendData.php",
                data: aData,
                cache: false,
                error: function(){
                    alert("Error");
                    },
                beforeSend: function(){
                  jContainer.html("<img src='img/loading.gif' style='margin-top:30px;'/><br/><span class='highlight'>Loading...</span>");
                },
                  success: function(strData){

                        var data = strData.split("#$#");
                        jContainer.html(data[0]);

                  }

            });
            
        }
        else if(search.length == 0){

            $j.ajax({
                type: "POST",
                url: "model/sendData.php",
                data: "section=videoList",
                cache: false,
                error: function(){
                    alert("Error");
                    },
                beforeSend: function(){
                  jContainer.html("<img src='img/loading.gif' style='margin-top:30px;'/><br/><span class='highlight'>Loading...</span>");
                },
                  success: function(strData){

                        var data = strData.split("#$#");
                        jContainer.html(data[0]);

                  }

            });

        }

   });

});



$j(function() {
    var slider = $j('#s3slider');
   if(slider.length > 0){
        slider.s3Slider({
            timeOut: 4000
        });
    }

});
