// BANNER SLIDER
function slider(uid) {
    $(uid).nivoSlider({
        effect: 'fade',
        directionNav: false,
        pauseTime: 3000,
        animSpeed: 400
    }); 
}

function sliderwthumb(uid) {
    $(uid).nivoSlider({
        effect: 'fade',
        directionNav: false,
        pauseTime: 3000,
        animSpeed: 400,
        controlNavThumbs:true,
        controlNavThumbsFromRel: true

    }); 
}

function sliderwothumb(uid) {
   
}

function langswitch() {
  var value=$('#lang :selected').val();
  if(value=="DE") location.replace("index.de.php?" + document.URL.split("?")[1]);
  if(value=="EN") location.replace("index.php?" + document.URL.split("?")[1]);
}
function langswitch2() {
  var value=$('#lang2 :selected').val();
  if(value=="DE") location.replace("index.de.php?" + document.URL.split("?")[1]);
  if(value=="EN") location.replace("index.php?" + document.URL.split("?")[1]);
}

$(window).load(function () {
    slider("#a3Banner");
});

// Jump to Element
function scrollGo() {
   var x = $("#a3Banner").offset().top - 100; // 100 provides buffer in viewport
   $('html,body').animate({scrollTop: x}, 500);
}

// HOVER EFFECTS
$(document).ready(function(){  
    $("#a3Navi .x2").mouseover(function(){  
      $("#hvlogo").attr('src', 'vis/ico/mcolor.png');
    });
    $("#a3Navi .x2").mouseout(function(){  
      $("#hvlogo").attr('src', 'vis/ico/m.png');
    });
});
// FIX HEIGHTS
function equalHeights() {
    $a = $("#a3Content");
    $b = $("#a3Sidebar");

    if ($b.height() <= $a.height()) $b.height($a.height());
    else $a.height($b.height());
}

$(document).ready(function () {
    equalHeights();
});

$(document).ready(function () {
  $(".list li:nth-child(2n)").css('background-color', '#f8f6f1');
  $(".list li:nth-child(2n-1)").css('color', '#6a5e43');
});

// FORM PLACEHOLDER
$(document).ready(function(){  
    function placeholder(){  
        $("input[type=text], input[type=password], textarea").each(function(){  
            var phvalue = $(this).attr("placeholder");  
            $(this).val(phvalue);  
        });  
    }  
    placeholder();  
    $("input[type=text], input[type=password], textarea").focusin(function(){  
        var phvalue = $(this).attr("placeholder");  
        if (phvalue == $(this).val()) {  
        $(this).val("");  
        }  
    });  
    $("input[type=text], input[type=password], textarea").focusout(function(){  
        var phvalue = $(this).attr("placeholder");  
        if ($(this).val() == "") {  
            $(this).val(phvalue);  
        }  
    });  
    
});
    
function showbar (byscript) {
      $stretch = $(".a3NewsBlock h2, .a3NewsBlock p, .a3NewsBlock, #a3Content, .a3ArticleBlock h2, .a3ArticleBlock p, .a3ArticleBlock, .a3ContentBlock h2, .a3ContentBlock p, .a3ContentBlock, .a3ContentBlock #msg, #video");
      
      if(byscript == false) {
      // Call PHP Script to set Cookie so save Navigation Status
        var url = 'incs/navcookie.jx.php';
        $.post(url, { status: "show" },
         function(data){
          void(0);
         });
      }
         
        // fix padding
        //$("#a3Content").css("padding", "57px 22px 0 22px");

        // change Switch button
        $("#a3HideBar, #a3ShowBar").animate({ top: 270 }, 500,
            function () {
                $("#a3HideBar").hide();
                $("#a3ShowBar").show();
            });

        // change Content
        $("#a3Sidebar .in").fadeOut(400,
            function () {
                $("#a3Sidebar .out").fadeIn(500);
            });

        // animation
        $("#a3Content").css("margin", "0");
        $stretch.animate({ width: '-=252' }, 500);


        $("#a3Sidebar").animate({ width: 309 }, 500,
            function () {
                $(document).ready(function () {
                    equalHeights();
                });
            });
}

function hidebar(byscript) {
        $stretch = $(".a3NewsBlock h2, .a3NewsBlock p, .a3NewsBlock, #a3Content, .a3ArticleBlock h2, .a3ArticleBlock p, .a3ArticleBlock, .a3ContentBlock h2, .a3ContentBlock p, .a3ContentBlock, .a3ContentBlock #msg, #video");
        
        if(byscript == false) {
          // Call PHP Script to set Cookie so save Navigation Status
          var url = 'incs/navcookie.jx.php';
          $.post(url, { status: "hide" },
           function(data){
            void(0);
           });
        }

        // change Switch button
        $("#a3ShowBar, #a3HideBar").animate({ top: 10 }, 500,
            function () {
                $("#a3ShowBar").hide();
                $("#a3HideBar").show();
            });

        // change Content
        $("#a3Sidebar .out").fadeOut(400,
            function () {
                $("#a3Sidebar .in").toggle(700);
            });

        // animation
        $("#a3Content").css("margin", "-63px 0 0 0");
        $stretch.animate({ width: '+=252' }, 700);
        //$("#a3Content").css("padding", "0 22px");

        $("#a3Sidebar").animate({ width: 57 }, 500,
            function () {

                if(typeof so!='undefined') so.write('container');
                $(document).ready(function () {
                    equalHeights();
                });
            });
}

// SIDEBAR SHOW/HIDE
$(document).ready(function () {

    // HIDE BAR
    $("#a3ShowBar, #a3ShowVid, #a3ShowVid2").click(function () {
        hidebar(false);
    });


    // SHOW BAR
    $("#a3HideBar").click(function () {
        showbar(false);
    });
    
});

// Tooltip
    this.tooltip = function () {
        /* CONFIG */
        xOffset = 0;
        yOffset = 15;

        $("a.tooltip").hover(function (e) {
            this.t = this.title;
            this.title = "";

            if ($(this).attr('class') == "tooltip m") $gender = "class='m'";
            else if ($(this).attr('class') == "tooltip w") $gender = "class='w'";
            else $gender = null;

            $("body").append("<p id='stdTooltip' " + $gender + "><span> " + this.t + "</span></p>");
            $("#stdTooltip")
			.css("top", (e.pageY - xOffset) + "px")
			.css("left", (e.pageX + yOffset) + "px")
			.show();
        },
	function () {
	    this.title = this.t;
	    $("#stdTooltip").remove();
	});
        $("a.tooltip").mousemove(function (e) {
            $("#stdTooltip")
			.css("top", (e.pageY - xOffset) + "px")
			.css("left", (e.pageX + yOffset) + "px");
        });
    };


// starting the script on page load
$(document).ready(function () {
    tooltip();
    
    //Fancybox fuer ArticleBanner
    $("a[rel=articleimgs]").fancybox({
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'titlePosition' 	: 'over',
				'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
					return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
				}
			});
    
    //change the main div to overflow-hidden as we can use the slider now
    $(".container").css('overflow','hidden');
    
    //calculate the height that the scrollbar handle should be
    var difference = $(".content").height()-$(".container").height();//eg it's 200px longer 
    var proportion = difference / $(".content").height();//eg 200px/500px
    var handleHeight = Math.round((1-proportion)*$(".container").height());//set the proportional height - round it to make sure everything adds up correctly later on
    
    //set up the slider 
    $(".indicator").slider({
    orientation: "vertical",
    range: "max",
    min: 0,
    max: 100,
    value: 100,
    slide: function(event, ui) {
    var topValue = -((100-ui.value)*difference/100);
    $(".content").css({top:topValue});//move the top up (negative value) by the percentage the slider has been moved times the difference in height
    }
    });
    
    //set the handle height and bottom margin so the middle of the handle is in line with the slider
    $(".ui-slider-handle").css({height:handleHeight,'margin-bottom':-0.5*handleHeight});
    	
    var origSliderHeight = $(".indicator").height();//read the original slider height
    var sliderHeight = origSliderHeight - handleHeight ;//the height through which the handle can move needs to be the original height minus the handle height
    var sliderMargin =  (origSliderHeight - sliderHeight)*0.5;//so the slider needs to have both top and bottom margins equal to half the difference
    $(".ui-slider").css({height:sliderHeight,'margin-top':sliderMargin});//set the slider height and margins
 
 
    // Athletes
    $('.abox').click(function() {
      var descr = $(this).children('.vitae').html();
      var name = $(this).children('.title').children('a').html();
      
      $(this).parent().children('.descr').html("<big><b><font style='display:inline-block; width: 415px; padding: 5px;background-color: #d9d700;color:white;text-align:center;'>"+name+"`s Vitae</font></b></big><br /><br />"+descr+"<br />");
      $(this).parent().children('.descr').css('background-color', 'white');
      $(this).parent().children('.descr').css('padding', '20px');
      $.blockUI({ message: $(this).parent().children('.descr') }); 
      $('.blockOverlay').click($.unblockUI); 
    });
    
    // Alter bereechnen fuer Order
    $('#bdate').blur(function() {
      val = $(this).val();
      date = val.split(".");
      var alter = 0;
    	var G_tag = date[0];
    	var G_monat = date[1];
    	var G_jahr = date[2];
      G_datum = new Date(date[0], date[1], date[2]);
    	H_datum = new Date();			
    	H_tag = H_datum.getDate();
    	H_monat = H_datum.getMonth();
    	H_jahr = H_datum.getYear();  
    	alter = H_datum.getYear() - G_jahr;
    	if(G_monat > H_monat) { alter = alter - 1; }
    	else if(G_monat == H_monat) { if(G_tag < G_monat) { alter = alter - 1; } }
    	alter = parseInt(alter);
      if(alter > 10 && alter < 150 ) $('#age').val(alter);
    } );
});

// Packages
$(window).load(function () {
  switchIt("#a3PackagesDetails > li", "#a3Packages > li", 0);
  switchIt("#a3CoachesDetails > li", "#a3Coaches > li", 0);
});

function switchIt(one, two, start) {
    var ac = 'active'; // Active Class
    start++;

    $(one).hide();
    $(one + ':nth-child(' + start + '), ' + two + ':nth-child(' + start + ')').show().addClass(ac).css('cursor', 'default');

    $(two).click(function () {
      if (!$(this).hasClass(ac)) {
        // get child index
        var e = $(this).parent().children().index(this);
        e = parseInt(e) + 1;

        // change cursor
        $(two).css('cursor', 'pointer');
        $(this).css('cursor', 'default');

        // show new entry
        $(one).hide();
        $(one + ':nth-child(' + e + ')').show().addClass(ac);

        // set new classes
        $(one + ", " + two).removeClass(ac);
        $(this).addClass(ac);
      }
    });
}
  
// Trailer Events auslesen
// Wenn Trailer fertig dann Navi wieder einblenden
var player = null;
function playerReady(obj)  {
        player = document.getElementsByName(obj.id)[0];
        //alert('the videoplayer '+obj['id']+' has been instantiated');
        player.addModelListener('STATE',     'stateMonitor');
}

function stateMonitor(obj) {
        currentState = obj['newstate'];
        if(currentState == 'PLAYING') {
          //alert ('the videoplayer '+obj['id']+'  is playing now!');
          // $VUslider.startStop(false);  // Trigger slideshow stop
        }
        if(obj.newstate == 'COMPLETED') {
          window.location.href = 'index.php';
        }
}
