
/* <![CDATA[ */
        function formatText(index, panel) {
		  return index + "";
	    }

        $(function () {

            if($('#searchq').val()!=defaultsearchstring){
              document.getElementById('searchq').style.color='#000000';
            }

            //Hide (Collapse) the toggle containers on load
			     // $(".toggle_container").hide();

			      //Switch the "Open" and "Close" state per click then slide up/down (depending on open/close state)
			      $(".trigger").click(function(){
				        $(this).toggleClass("active").next().slideToggle("slow");
			      });
			      $(".credittrigger").click(function(){
				        $(this).toggleClass("active").next().slideToggle("slow");
			      });
			      //open by default!
            //$(".trigger").click();
			
      $("a.highslide").fancybox({
				'titleShow'		: true,
				'titlePosition'	: 'over',
				'transitionIn'	: 'none',
				'transitionOut'	: 'none'
			});


	$("a#inline").fancybox({
		'hideOnContentClick':	false,
		'width'				:	350
	});
	
	
  //alert('huhu');
	// JQUERY SELECTBOX -- start replace within #page
	$("#page select.widerselect").selectbox({className:'wselect'});
	$("#page select").selectbox();
	$("#registration select").parents('.jquery-selectbox').unselectbox();
	$("#locker select").parents('.jquery-selectbox').unselectbox();
    $("#admin select").parents('.jquery-selectbox').unselectbox();
    $("#admin2 select").parents('.jquery-selectbox').unselectbox();
	$("#mainreg select").selectbox();
	

	$(".jquery-selectbox-item").click(function () {
	  $(".jquery-selectbox-item").removeClass("selected");
      $(this).addClass("selected");
    });
	
	$(".jquery-downloadbox-item").click(function () {
	  $(".jquery-downloadbox-item").removeClass("selected");
      $(this).addClass("selected");
    });

});

var responseshown=false;
function adminaction(what,whatid,whatelse,that){
     var genre=$('#featuredgenres').val();
     var gd=0;
     if($('#gdonly').attr('checked'))
      gd=1;
  //   alert( 'what='+what+'&id='+whatid+'&action='+whatelse+'&genre='+genre+'&gd='+gd);
	$.ajax({
           url: '/admin.php',
           dataType: 'json',
           type: 'post',
           data: 'what='+what+'&id='+whatid+'&action='+whatelse+'&genre='+genre+'&gd='+gd,
           success: function(data) {
    //         alert(data.action+' '+that);
              if(data.action=='reload')
                 window.location.href=window.location.href;
	      else{
	        $('#'+that).unbind();
	        $('#'+that).click(
                 function(){
                   adminaction(what,whatid,data.action,that);
                 }
                );
              $('#'+that).text(data.text);
	      }
           }
       });
}
function makenotable(){
   $('#nfeedback').text('storing...');
   $.ajax({
           url: '/admin.php',
           dataType: 'json',
           type: 'post',
           data: $('#noteableform').serialize(),
           success: function(data) {
             if(data.text!=''){
                 $('#nb'+data.genre).remove();
                 $('#nfeedback').text(data.text);
                 $('#allnotables').append("<span id=\"nb"+data.genre+"\">"+data.newstuff+" <a href=\"#\" onclick=\"removenotable("+data.id+","+data.genre+",'nartist');return false;\">DELETE</a><br/></span>");
             }
           }
       });
}
function removenotable(a,b,c){
   $('#nfeedback').text('deleting...');
   $.ajax({
           url: '/admin.php',
           dataType: 'json',
           type: 'post',
           data: 'what='+c+'&id='+a+'&genre='+b+'&action=remove',
           success: function(data) {
             $('#nb'+data.genre).remove();
             $('#nfeedback').text(data.text);
           }
       });
}
function show_response(data,action,type,main){
  var tstring='cart';
  if(main=='memo')
     tstring='memo';
  var newcontent='';
  if(data.error){
     newcontent=data.error;
  }
  else{
  var astring='added to';
  if(action!='add')
     astring='removed from';

   if(data.upc)
       type=data.ptype;
   newcontent='The '+type+' "'+data.name+'" has been '+astring+' your '+tstring;
   }
   $('#added-to-'+tstring+'-span').html(newcontent);
   $('#added-to-'+tstring).fixedCenter();
   if(responseshown) clearTimeout(responseshown);
   $('#added-to-'+tstring).fadeIn(500);
   responseshown=setTimeout(
           function(){
                $('#added-to-memo').fadeOut(500);
				$('#added-to-cart').fadeOut(500);
           },
           2000
   );
}
function update_items(type,id,action,morc){
    if(morc=='cart'){
      var c1='buy';
      var c2='bought';
      if(action!='add'){
          c1='bought';
          c2='buy';
      }
    }
    else{
      var c1='memo';
      var c2='memo-done';
      if(action!='add'){
          c1='memo-done';
          c2='memo';
      }
    }
    $('#'+morc+'_'+type+'_'+id).removeClass(c1);
    $('#'+morc+'_'+type+'_'+id).addClass(c2);
    var i=1;
    while($('#'+morc+'_'+type+'_'+id+'_'+i).length>0){
       $('#'+morc+'_'+type+'_'+id+'_'+i).removeClass(c1);
       $('#'+morc+'_'+type+'_'+id+'_'+i).addClass(c2);
       i++;
    }
}
function in_cart(type,id,add,force){
   var action='delete';
   if(force!==undefined)
     action=force;
   else
    if(!$('#cart_'+type+'_'+id).hasClass('bought'))
       action='add';
       $.ajax({
           url: '/cartmemoajax.php',
           dataType: 'json',
           type: 'post',
           data: 'object='+type+'&id='+id+'&main=cart&action='+action,
           success: function(data) {
             if(!data.error){
               update_items(type,id,action,'cart');
             }
             show_response(data,action,type,'cart');
         }
       });
}
function remove_cm(type,id,cartormemo){
    var action='delete';
    //alert('object='+type+'&id='+id+'&main='+cartormemo+'&action='+action);
    $.ajax({
           url: '/cartmemoajax.php',
           dataType: 'json',
           async:   false,
           type: 'post',
           data: 'object='+type+'&id='+id+'&main='+cartormemo+'&action='+action,
           success: function(data) {
            // alert(parseInt($('#totalitems').text()));
             $('#totalitems_'+cartormemo).text(parseInt($('#totalitems_'+cartormemo).text())-1+' Items');
             $('#'+type+'count_'+cartormemo).text(parseInt($('#'+type+'count_'+cartormemo).text())-1);
             $('#totalitems_'+cartormemo+'_1').text(parseInt($('#totalitems_'+cartormemo+'_1').text())-1+' Items');
             $('#'+type+'count_'+cartormemo+'_1').text(parseInt($('#'+type+'count_'+cartormemo+'_1').text())-1);

             if(cartormemo=='cart'){
                oldprice=parseFloat($('#price'+type+id).text());
                if(isNaN(oldprice)) oldprice=0;
                $('#grandtotal').text((parseFloat($('#grandtotal').text())-oldprice).toFixed(2));
                $('#grandtotal_1').text((parseFloat($('#grandtotal_1').text())-oldprice).toFixed(2));
                update_items(type,id,action,'cart');
               //$('#cart_'+type+'_'+id).removeClass('bought');
               // $('#cart_'+type+'_'+id).addClass('buy');
             }
             else{
               update_items(type,id,action,'memo');

             }
             $('#listitem_'+type+'_'+id).remove();
             $('#listitem_'+type+'_'+id+'_1').remove();
           }
       });
}
function in_memo(type,id,add,force){
   var action='delete';
   if(force!==undefined)
     action=force;
   else
   if(!$('#memo_'+type+'_'+id).hasClass('memo-done'))
       action='add';
       $.ajax({
           url: '/cartmemoajax.php',
           dataType: 'json',
           type: 'post',
           data: 'object='+type+'&id='+id+'&main=memo&action='+action,
           success: function(data) {
             if(!data.error){
               update_items(type,id,action,'memo');
             }
             show_response(data,action,type,'memo');
           }
       });
}
var defaultsearchstring='Search Music...';
function buildquery(that){
   var s=$('#searchq').val();
   if(s!='' && s!=defaultsearchstring){
     var theq=$('#searchq').val();
     //theq=theq.replace(/[\/,%,&,']/g,' ');
     var q='/search/'+escape(encodeURIComponent(theq))+'/Result.html';
     document.location.replace(q);
   }
   return false;
}
function dosearch(that){
   if($('#searchtype').val()!=0 && $('#searchq').val()!='' && $('#searchq').val()!=defaultsearchstring)
      buildquery(that);
   else if($('#searchtype').val()==64)
      $("#searchq").autocomplete("destroy");
   else
      $( "#searchq" ).autocomplete({

      source: function(request,response){
        $.ajax(
          {
            url: '/suggest.php',
            dataType: 'json',
            data:{
              term: request.term,
              searcht:$('#searchtype').val()
            },
            success: function(data) {
              response(data);
            }
          }
        );
      },
			minLength: 3,
			select: function(event,ui){
         document.location.href=ui.item.url;
         return false;
      }
		});
}
/* ]]> */


$(document).ready(function(){
 
	$("ul.nav2").parent().append("<div></div>"); //Only shows drop down trigger when js is enabled (Adds empty div tag after ul.nav2*)
 
	$("ul.topnav li div").mouseover(function() { //When trigger is clicked...
 
		//Following events are applied to the nav2 itself (moving nav2 up and down)
		$(this).parent().find("ul.nav2").slideDown('fast').show(); //Drop down the nav2 on click
 
		$(this).parent().hover(function() {
		}, function(){
			$(this).parent().find("ul.nav2").slideUp('fast'); //When the mouse hovers out of the nav2, move it back up
		});
 
		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() {
			$(this).addClass("subhover"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
	});
 
});
$(window).load(function() { 
$("img.thumb, img.thumb_banner").each(
   function(i){
        if (!this.complete || (!$.browser.msie && (typeof this.naturalWidth == "undefined" || this.naturalWidth == 0))) {
	      $(this).attr('rsrc',$(this).attr('src'));
        var ppartsimg=$(this).attr('src').split('_');
        var ppsize=ppartsimg[ppartsimg.length-1].substring(0,ppartsimg[ppartsimg.length-1].indexOf('.'));
        var ppimg=$(this).attr('src').split('/');
        var defimg='loader-'+ppsize+'.gif';
      /*  if(ppimg[2]=="album")
           defimg='default_cover_'+ppartsimg[ppartsimg.length-1];
        if(ppimg[2]=="artist")
           defimg='artist_nopic_'+ppartsimg[ppartsimg.length-1];
      */
        if(defimg!='' && ppsize!=''){
	       $(this).attr('src',"/imgcache/"+defimg);
          var aObj = $(this);
          $.ajax({
           url: '/getimg.php',
           dataType: 'json',
           type: 'get',
           data: 'url='+$(this).attr('rsrc'),
           success: function(data) {
              imgup=false;
              if(data.url)
                 aObj.attr('src',data.url+'?re');
           }
          });
        }
   }
   }
 );
});


// Scroll to Top Funktion
$(document).ready(function() {
    $('a[href=#top]').click(function(){
        $('html, body').animate({scrollTop:0}, 'slow');
        return false;
    });
});

$(document).ready(function(){
	// check for what is/isn't already checked and match it on the fake ones
	$("input:checkbox").each( function() {
		(this.checked) ? $("#fake"+this.id).addClass('stylechecked') : $("#fake"+this.id).removeClass('stylechecked');
	});
	// function to 'check' the fake ones and their matching checkboxes
	$(".stylecheck").click(function(){
		($(this).hasClass('stylechecked')) ? $(this).removeClass('stylechecked') : $(this).addClass('stylechecked');
		$(this.hash).trigger("click");
		return false;
	});
});

$.simplePrint = function(selector)
{
    printArea = document.createElement('iframe');
    $(printArea).attr({style: 'border:0;position:absolute;width:0px;height:0px;left:0px;top:0px;'});
    document.body.appendChild(printArea);
    printArea.doc = printArea.contentWindow.document;
    printArea.doc.open();
    printArea.doc.write($(selector).html());
    printArea.doc.close();
    printArea.contentWindow.focus();
    printArea.contentWindow.print();
    return false;
    document.body.removeChild(printArea);
}

