﻿

/*******************************************************************
 ** cDialog
 *******************************************************************/

function cDialog(strDialogType) {

  this.html= function(x) {
    html = x;

    //$(".dialog_close").click();

    $("body").append('<div class="dialogwrapper d_'+strDialogType+'" style="top:' + $(window).scrollTop() + 'px;"><div class="d_shadow"><a href="#" id="dialog_close">Stäng</a><div class="dialog_border"><div class="dialog_content">'+html+'<div class="clear"></div></div></div></div></div>');
    $(".dialogwrapper").fadeIn();
    $("#dialog_close").click(function(){
      $(this).parent().parent().fadeOut().remove(1000);
      return false;
    })
  }
}
var cCrunchyrollDialog = new cDialog("crunchyroll");
var cVideoDialog = new cDialog("video");
var cDialog = new cDialog("normal");


function openLogIn() {
  cDialog.html(''
              +'<div style="padding: 10px; width:407px;">'
              +'     <div id="login_dialog_login">'
              +'          <div class="title">Sugen på att logga in?</div>'
              +'          <div style="padding: 10px;">'
              +'               <form action="'+root+'members/login/login.asp" method="post" id="form_dialog_login" onSubmit="return postLogin(this.id)">'
              +'                     &nbsp;&nbsp;<small>Användarnamn</small>'
              +'                     <br /><input type="text" tabindex="101" name="username" style="font-size: 18px; padding: 5px; border: 1px solid #ccc; -moz-border-radius: 5px;-khtml-border-radius: 5px;-webkit-border-radius: 5px;border-radius: 5px;" />'
              +'                     <input type="submit" tabindex="103" class="button small" value="Logga in &raquo;" />'
              +'                     <div class="clear"></div>'
              +'                     &nbsp;&nbsp;<small>Lösenord</small>'
              +'                     <br /><input type="password" tabindex="102" name="password" style="font-size: 18px; padding: 5px; border: 1px solid #ccc; -moz-border-radius: 5px;-khtml-border-radius: 5px;-webkit-border-radius: 5px;border-radius: 5px;" />'
              +'                     <a href="#" onClick="$(\'#login_dialog_login\').fadeOut(300);$(\'#login_dialog_lostpass\').wait(300).fadeIn(300);return false;" style="font-weight: bold;">Glömt lösenordet?</a>'
              +'                     <div class="clear"></div>'
              +'               </form>'
              +'          </div>'
              +'     </div>'
              +'     <div id="login_dialog_lostpass" style="display: none;">'
              +'          <a href="#" onClick="$(\'#login_dialog_lostpass\').fadeOut(300);$(\'#login_dialog_login\').wait(300).fadeIn(300);return false;" style="font-weight: bold;float: right;margin-top:5px;">Jag vill logga in!</a>'
              +'          <div class="title">Glömt lösenordet?</div>'
              +'          <div style="padding: 10px;">'
              +'               Fyll i den epostadress som står angiven i din profil så kommer vi att skicka ett nytt lösenord till dig. Du kan ändra lösenordet senare.'
              +'               <form action="'+root+'members/login/lostpass.asp" method="post" id="form_dialog_lostpass" onSubmit="return postLostpass(this.id)">'
              +'                     <br /><input type="text" tabindex="101" name="email" style="font-size: 18px; padding: 5px; border: 1px solid #ccc; -moz-border-radius: 5px;-khtml-border-radius: 5px;-webkit-border-radius: 5px;border-radius: 5px;" />'
              +'                     <input type="submit" class="button small" tabindex="102" value="Skicka nytt lösenord" />'
              +'               </form>'
              +'          </div>'
              +'     </div>'
              +'</div>'
              +'<div style="border-top: 1px solid #ccc; background: #eee; font-weight: bold; padding:10px;">'
              +'     Inget konto? <a href="'+root+'members/register/">Registrera dig</a>!'
              +'</div>'
  )
}


function openLogOut() {
  cDialog.html(''
              +'<div style="padding: 10px;"> '
              +'     <div class="title">Är du säker på att du vill logga ut?</div>'
              +'     <center style="margin:10px 35px 5px;">'
              +'             <a href="'+root+'members/login/logout.asp" class="button">Jajjamän!</a> &nbsp;&nbsp;'
              +'             <a href="#" onClick="$(\'#dialog_close\').click();return false;" class="button">Naeh...</a>'
              +'     </center>'
              +'</div>'
  )
}

function supports_html5_storage() {
  try {
    return 'localStorage' in window && window['localStorage'] !== null;
  } catch (e) {
    return false;
  }
}

/* Localstorage-grejer från THS.

if (supports_html5_storage()) {
	if(localStorage.faves) {
		arrFaves = JSON.parse(localStorage.faves)
	} else {
		localStorage.faves = "[]"
		arrFaves = JSON.parse(localStorage.faves)
	}
}

*/

function crunchyroll_toggle_watched(cr_id) {
	intIndex = $.inArray(cr_id,arrCRWatched) // finns klippet med så returneras platsen på denna i arrayen, annars blir det -1
	
	if (intIndex == -1) {
		arrCRWatched.push(cr_id)
		localStorage.CrunchyrollWatched = JSON.stringify(arrCRWatched)
		$(".crunchyroll_watch_button").removeClass("unwatched").addClass("watched").html("Markera som osedd")
	} else {
		arrCRWatched.splice(intIndex,1)
		localStorage.CrunchyrollWatched = JSON.stringify(arrCRWatched)
		$(".crunchyroll_watch_button").removeClass("watched").addClass("unwatched").html("Markera som sedd")
	}
	crunchyroll_update_watched_videos();
}

function crunchyroll_update_watched_videos() {
	$(".crunchyroll_video_button").css({opacity:1})
	$.each(arrCRWatched, function(i,item){
		$("#crunchyroll_video_button-"+item).css({ opacity: 0.3 });
	});

}

function openCrunchyroll(cr_id) {
	intPlayerWidth = Math.round(intPlayerHeight*1.7777)
	intCRPlayerHeight = intPlayerHeight+25
	intCRVideoFormat = 102; // dunno?
	
	if (supports_html5_storage()) {
	
		if ($.inArray(cr_id,arrCRWatched) == -1) {
			strCRWatchedButton = '<li class="crunchyroll_watch_button unwatched" onClick="crunchyroll_toggle_watched('+cr_id+')">Markera som sedd</li>'
		} else {
			strCRWatchedButton = '<li class="crunchyroll_watch_button watched" onClick="crunchyroll_toggle_watched('+cr_id+')">Markera som osedd</li>'
		}
		
		intCRVideoQuality = localStorage.CrunchyrollQuality
	} else {
		strCRWatchedButton = "";
		intCRVideoQuality = 10; //0/10 = SD, 20 = 480p, 30 = 720p... fungerar!
	}
	
	strCRQualityButtons = '<ul><li class="crunchyroll_quality_10">SD</li><li class="crunchyroll_quality_20" title="480p fungerar endast om du har ett premiumkonto hos Crunchyroll.">480p</li><li class="crunchyroll_quality_30" title="720p fungerar endast om du har ett premiumkonto hos Crunchyroll samt om videon finns i 720p-kvalite.">720p</li> '+strCRWatchedButton+'<li style="float:right;" onClick="location.href=\'http://www.crunchyroll.com/media-'+cr_id+'\'">Crunchyroll</li></ul>'
	
	cCrunchyrollDialog.html('<div class="crunchyroll_player_code"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab" width="'+intPlayerWidth+'" height="'+intCRPlayerHeight+'"><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><param name="wmode" value="transparent"></param><param name="quality" value="high"></param><param name="movie" value="http://www.crunchyroll.com/swf/vidplayer.swf"></param><param name="flashvars" value="config_url=http%3A%2F%2Fwww.crunchyroll.com%2Fxml%2F%3Freq%3DRpcApiVideoPlayer_GetStandardConfig%26media_id%3D'+cr_id+'%26video_format%3D'+intCRVideoFormat+'%26video_quality%3D'+intCRVideoQuality+'%26auto_play%3D1%26aff%3Daf-91648-smms%26click_through%3D0"></param><embed type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" allowFullScreen="true" allowScriptAccess="always" wmode="transparent" quality="high" src="http://www.crunchyroll.com/swf/vidplayer.swf" width="'+intPlayerWidth+'" height="'+intCRPlayerHeight+'" flashvars="config_url=http%3A%2F%2Fwww.crunchyroll.com%2Fxml%2F%3Freq%3DRpcApiVideoPlayer_GetStandardConfig%26media_id%3D'+cr_id+'%26video_format%3D'+intCRVideoFormat+'%26video_quality%3D'+intCRVideoQuality+'%26auto_play%3D1%26aff%3Daf-91648-smms%26click_through%3D0"></embed></object></div><div class="crunchyroll_controls">'+strCRQualityButtons+'<div class="clear"></div></div>')

	$(".crunchyroll_quality_"+intCRVideoQuality).addClass("current")
	
	$(".crunchyroll_quality_10").click(function(){
		$(".crunchyroll_quality_"+intCRVideoQuality).removeClass("current")
		$(this).addClass("current")
		$(".crunchyroll_player_code").html($(".crunchyroll_player_code").html().replace("video_quality%3D"+intCRVideoQuality,"video_quality%3D10"))
		intCRVideoQuality = 10
		if (supports_html5_storage()) {
			localStorage.CrunchyrollQuality = intCRVideoQuality
		}
	})
	$(".crunchyroll_quality_20").click(function(){
		$(".crunchyroll_quality_"+intCRVideoQuality).removeClass("current")
		$(this).addClass("current")
		$(".crunchyroll_player_code").html($(".crunchyroll_player_code").html().replace("video_quality%3D"+intCRVideoQuality,"video_quality%3D20"))
		intCRVideoQuality = 20
		if (supports_html5_storage()) {
			localStorage.CrunchyrollQuality = intCRVideoQuality
		}
	})
	$(".crunchyroll_quality_30").click(function(){
		$(".crunchyroll_quality_"+intCRVideoQuality).removeClass("current")
		$(this).addClass("current")
		$(".crunchyroll_player_code").html($(".crunchyroll_player_code").html().replace("video_quality%3D"+intCRVideoQuality,"video_quality%3D30"))
		intCRVideoQuality = 30
		if (supports_html5_storage()) {
			localStorage.CrunchyrollQuality = intCRVideoQuality
		}
	})
	
	return false;
}

function openYouTube(yt_id) {
  intPlayerWidth = Math.round(intPlayerHeight*1.7777)
  intYTPlayerHeight = intPlayerHeight+25
  cVideoDialog.html('<object width="'+intPlayerWidth+'" height="'+intYTPlayerHeight+'" style="margin-bottom:-4px;"><param name="movie" value="http://www.youtube.com/v/'+yt_id+'&hl=sv&fs=1"></param><param name="wmode" value="opaque"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'+yt_id+'&hl=sv&fs=1" type="application/x-shockwave-flash" wmode="opaque" width="'+intPlayerWidth+'" height="'+intYTPlayerHeight+'" allowscriptaccess="always" allowfullscreen="true"></embed></object>')
}
function openNicoVideo(video_id) {
	intPlayerWidth = Math.round(intPlayerHeight*1.3333)
	cVideoDialog.html('<iframe src="'+root+'_js/nicovideo_iframe.asp?id='+video_id+'" width="'+intPlayerWidth+'" height="'+intPlayerHeight+'" style="z-index:199;border:0;"></iframe>')
}

function openVimeo(video_id) {
  intPlayerWidth = Math.round(intPlayerHeight*1.7777)
  cVideoDialog.html('<object width="'+intPlayerWidth+'" height="'+intPlayerHeight+'" style="margin-bottom:-4px;"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id='+video_id+'&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /><param name="wmode" value="opaque"></param><embed wmode="opaque" src="http://vimeo.com/moogaloop.swf?clip_id='+video_id+'&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="'+intPlayerWidth+'" height="'+intPlayerHeight+'"></embed></object>');
}

function openVideoPlayer(video_id) {
  cVideoDialog.html('<div id="video_title" style="z-index: 10;display: none;position: absolute; top: 2px; left: 20px; font-size: 140%; color: #FFF;"><i>Laddar titel...</i></div>'
  + '<div id="video_title_shadow" style="z-index: 5; display: none; position: absolute; top: 0; left: 0; width: 100%; height: 30px; background: #000;opacity:.6;filter:alpha(opacity=60); "></div>'
  + '<div id="fp_player" style="width:'+Math.round(intPlayerHeight*1.7777)+'px;height:'+intPlayerHeight+'px;">'
  + '     <div style="text-align:center;color:#fff; padding-top:100px;">'
  + '          <span style="font-size:40px;font-weight:bold;letter-spacing:-1px;">Laddar videospelare!</span>'
  + '          <br />Det bör gå ganska fort, tar det dock ett sekel eller två så är det nog någonting som inte fungerar...'
  + '     </div>'
  + '</div>')

  $.getJSON(root + "_ajax/VideoData.asp?id="+video_id,function(data){
        $("#video_title").html(data.title);
        
        //intPlayerHeight = 480;   - Nu definerad detta uppe i toppen
        switch(data.aspect_ratio) {
            case "4:3" : intPlayerWidth = Math.round(intPlayerHeight*1.3333)
          break;
            default : intPlayerWidth = Math.round(intPlayerHeight*1.7777)
        }
        $("#fp_player").height(intPlayerHeight);
        $("#fp_player").width(intPlayerWidth);


        $("#fp_player").html('');
        fpPlayerConfig.clip.url = "http://static.genshiken.se/videos/"+video_id;
        fpPlayerConfig.plugins.content.width = intPlayerWidth-100;
        fpPlayerConfig.plugins.controls.width = intPlayerWidth-110;
        flowplayer("fp_player", fpMetaConfig, fpPlayerConfig );
  });

  $(".d_shadow").hover(
    function () {
      $("#video_title").fadeIn();
      $("#video_title_shadow").fadeIn();
    },
    function () {
      $("#video_title").fadeOut();
      $("#video_title_shadow").fadeOut();
    }
  );
}

/***********************************************************************
 *** cDialog END
 ***********************************************************************/




function infotabs(id) {
      document.getElementById('tab1').className = ""
      document.getElementById('tab2').className = ""
      document.getElementById('tab3').className = ""
      document.getElementById('tab4').className = ""
	  document.getElementById('tab5').className = ""
      document.getElementById('tab' + id).className = "on"
      document.getElementById('tab1Content').style.display = "none"
      document.getElementById('tab2Content').style.display = "none"
      document.getElementById('tab3Content').style.display = "none"
      document.getElementById('tab4Content').style.display = "none"
	  document.getElementById('tab5Content').style.display = "none"
      document.getElementById('tab'+id+'Content').style.display = "block"
}


function changeHTML(from_id,to_id) {
  document.getElementById(to_id).innerHTML = document.getElementById(from_id).innerHTML
}


// RedirectConfirm. OK / Avbryt-ruta dyker upp.
function RedCon(msg, url) {
  if (confirm(msg)) {
    location.href=url;
  }
  return false;
}


function RandomInt() {
  return Math.floor(Math.random()*99999999999);
}

function ajax_notice(formID,inData) {
  strResponseCode = inData.substring(0,1)
  strResponse = inData.substring(2)
  strRandom = RandomInt();

  if(strResponseCode == "1") {
    $("#"+formID).append("<div id='" + strRandom + "' class='abox_positive'>" + strResponse + "</div>")
    $("#"+strRandom).slideDown().wait(3000).slideUp();

  } else if(strResponseCode == "0") {
    $("#"+formID).append("<div id='" + strRandom + "' class='abox_negative'>" + strResponse + "</div>")
    $("#"+strRandom).slideDown().wait(3000).slideUp();
  } else if(strResponseCode == "2") {
    $("#"+formID).append("<div id='" + strRandom + "' class='abox_neutral'>" + strResponse + "</div>")
    $("#"+strRandom).slideDown().wait(3000).slideUp();
  }
  return strResponseCode
}

function postLostpass(formID) {
	$("#"+ formID + " input[name='email']").attr("disabled","disabled");
	$("#"+ formID + " input[type='submit']").val("Skickar...").attr("disabled","disabled");
	$.ajax({
		type: "POST",
		url: root+"members/login/lostpass_a.asp",
		data: "email=" + encodeURIComponent($("#"+ formID + " input[name='email']").val()),
		success: function(msg){
			ajax_notice(formID,msg);
			$("#"+ formID + " input[name='email']").val("").removeAttr("disabled");
			$("#"+ formID + " input[type='submit']").val("Skicka nytt lösenord").removeAttr("disabled");
		}
	});
  return false;
}

function postLogin(formID) {

  $.ajax({
     type: "POST",
     url: root+"members/login/login_a.asp",
     data: "username=" + encodeURIComponent($("#" + formID + " input[name='username']").val())
         + "&password=" + encodeURIComponent($("#" + formID + " input[name='password']").val()),
     success: function(msg){
       if (ajax_notice(formID,msg) == 1){
         location.reload(true);
       }
     }
  });
  return false;
}




/*
function viewSeason(intID) {
  document.getElementById('seasonTab' + intID).className = "seasonTabOn"
  document.getElementById('seasonContent').innerHTML = document.getElementById('season'+intID).innerHTML
} */



/*
function RedCon2(msg){
  return confirm(msg);
}



function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}



*/ 
