/* FUNCTIONS
------------------------------------------------------------------------------*/

  /* MAILTO
  ------------------------------------------------------------------------------*/

  function mailTo(name,domain){
  	location.href = "mailto:" + name + "@" + domain;
  }

  /* OPEN POPUP > BYTEFM
  ----------------------------------------------------------------------------*/

  function openByteFM(){
    var win = null;
    var url = "http://www.byte.fm/player/embedded/open.php";
    var w = 220;
    var h = 550;
    myleft=(screen.width)?(screen.width-w)/2:100;mytop=(screen.height)?(screen.height-h)/2:100;
    settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no";
    win=window.open(url,'bytefm',settings);
    win.focus();
  }

  /* NL > OPEN DIV
  ----------------------------------------------------------------------------*/

  function openNL(){
    $('#nlform').show();
    $.fn.colorbox.init();
    $.fn.colorbox({width:"360px", height:"300px", inline:true, href:"#nlform"});
  }

  /* NL > UPDATE
  ----------------------------------------------------------------------------*/

  function updateNL(){

    $('#err_1').hide();
    $('#err_2').hide();
    $('#err_3').hide();
    $('#ok_1').hide();
    $('#ok_2').hide();

  	var url = '/inc/reqs/nl.php';

    $.ajax({
      type: "POST",
      data: $('#formnl').serialize(),
      url: url,
      context: document.body,
      success: function(msg){
      if(msg == 'err_1'){
        $("#err_1").fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100);
      }else if(msg == 'err_2'){
        $("#err_2").fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100);
      }else if(msg == 'err_3'){
        $("#err_3").fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100);
      }else{
        if(msg == 'ok_1'){
          $('#ok_1').show();
        }else{
          $('#ok_2').show();
        }
        $('#email').val('');
        $('#formnl').hide();
        //$('#nlform').hide();
      }
    }});

  }

  /* CONTACT
  ----------------------------------------------------------------------------*/

  function sendContact(){

    $('#err_1').hide();
    $('#err_2').hide();
    $('#ok').hide();

  	var url = '/inc/reqs/contact.php';

    $.ajax({
      type: "POST",
      data: $('#contact').serialize(),
      url: url,
      context: document.body,
      success: function(msg){
      if(msg == 'err_1'){
        $("#err_1").fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100);
      }else if(msg == 'err_2'){
        $("#err_2").fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100);
      }else{
        $('#sendok').show();
        $('#name').val('');
        $('#email').val('');
        $('#web').val('');
        $('#message').val('');
        $('#contact').hide();
      }
    }});

  }


  /* COUNT HITS
  ----------------------------------------------------------------------------*/

  function countHits(id,cat){

  	var url = '/inc/reqs/counthits.php';

    $.ajax({
      type: "POST",
      data: "&id="+id+"&cat="+cat,
      url: url,
      context: document.body,
    });

  }


  /* SHARE > FACEBOOK / TWITTER
  ----------------------------------------------------------------------------*/

  function shareFacebook(url, title){
    window.open('http://www.facebook.com/sharer.php?u='+url+'&t='+title+'', 'facebook','toolbar=no,width=700,height=400');
  }

  function shareTwitter(url, title){
    window.open('http://www.twitter.com/home?status='+title+url+'', 'twitter','toolbar=no,width=700,height=400');
  }

  /* CHANGE MIXTAPE
  ----------------------------------------------------------------------------*/

  function changeMixtape(vol){
    if($('#vol').val() == ''){
      window.location.href = "/mixtapes";
    }else{
      window.location.href = "/mixtape/" + $('#vol').val();
    }
  }

  /* BLANKWIN
  /* written by Alen Grakalic, provided by Css Globe (cssglobe.com)
  /* http://cssglobe.com/post/1281/open-external-links-in-new-window-automatically/
  ------------------------------------------------------------------------------*/

  this.blankwin = function(){
  	var hostname = window.location.hostname;
  	hostname = hostname.replace("www.","").toLowerCase();
  	var a = document.getElementsByTagName("a");
  	this.check = function(obj){
  		var href = obj.href.toLowerCase();
  		return (href.indexOf("http://")!=-1 && href.indexOf(hostname)==-1) ? true : false;
  	};
  	this.set = function(obj){
  		obj.target = "_blank";
  		//obj.className = "";
  	};
  	for (var i=0;i<a.length;i++){
  		if(check(a[i])) set(a[i]);
  	};
  };



  // script initiates on page load.

  this.addEvent = function(obj,type,fn){
  	if(obj.attachEvent){
  		obj['e'+type+fn] = fn;
  		obj[type+fn] = function(){obj['e'+type+fn](window.event );}
  		obj.attachEvent('on'+type, obj[type+fn]);
  	} else {
  		obj.addEventListener(type,fn,false);
  	};
  };
  addEvent(window,"load",blankwin);

