/*
 * 	Easy Slider 1.7 - jQuery plugin
 *	written by Alen Grakalic	
 *	http://cssglobe.com/post/4004/easy-slider-15-the-easiest-jquery-plugin-for-sliding
 *
 *	Copyright (c) 2009 Alen Grakalic (http://cssglobe.com)
 *	Dual licensed under the MIT (MIT-LICENSE.txt)
 *	and GPL (GPL-LICENSE.txt) licenses.
 *
 *	Built for jQuery library
 *	http://jquery.com
 *
 */
 
/*
 *	markup example for $("#slider").easySlider();
 *	
 * 	<div id="slider">
 *		<ul>
 *			<li><img src="images/01.jpg" alt="" /></li>
 *			<li><img src="images/02.jpg" alt="" /></li>
 *			<li><img src="images/03.jpg" alt="" /></li>
 *			<li><img src="images/04.jpg" alt="" /></li>
 *			<li><img src="images/05.jpg" alt="" /></li>
 *		</ul>
 *	</div>
 *
 */
var reedsuitgevoerd = 0;	
(function($)
{
    $.fn.easySlider = function(options)
    {
        // default configuration properties
        var defaults = {
            prevId:         'prevBtn',
            prevText:       '',
            nextId:         'nextBtn',
            nextText:       '',
            controlsShow:   true,
            controlsBefore: '',
            controlsAfter:  '',
            controlsFade:   true,
            insertAfter:    true,
            firstId:        'firstBtn',
            firstText:      'First',
            firstShow:      false,
            lastId:         'lastBtn',
            lastText:       'Last',
            lastShow:       false,
            vertical:       false,
            speed:          800,
            ease:           'swing',
            auto:           false,
            pause:          2000,
            continuous:     false,
            prevNext:       true,
            numeric:        false,
            numericId:      'controls'
        };

        var options = $.extend(defaults, options);

        this.each(function()
        {
			// call to Flash function 
			


            var obj = $(this);

            // Fix for nested list items
            var ul = obj.children("ul");
            var li = ul.children("li");

            var s = li.length;
            var w = obj.width();
            var h = obj.height();

            var t = 0;
            var ts = s-1;
            var clickable = true;

            // Set obj overflow to hidden
            obj.css("overflow","hidden");

            // Set width/height of list items based on width/height of obj
            li.each(function() {
               if(options.vertical) $(this).height(h);
                else $(this).width(w);
            });

            // Float items to the left
            li.css('float', 'left');

            // Set width/height of ul
            if(options.vertical) ul.height(s*w);
            else ul.width(s*h);

            // Clone elements for continuous scrolling
            if(options.continuous)
            {
                if(options.vertical)
                {
                    ul.prepend(li.filter(":last-child").clone().css("margin-top","-"+ h +"px"));
                    ul.append(li.filter(":nth-child(2)").clone());
                    ul.height((s+1)*h);
                } else {
                    ul.prepend(li.filter(":last-child").clone().css("margin-left","-"+ w +"px"));
                    ul.append(li.filter(":nth-child(2)").clone());
                    ul.width((s+1)*w);
                }
            };

            if(options.controlsShow)
            {
                var html = options.controlsBefore;
                if(options.numeric){
                    html += '<div class="footback" id="footbackjs" style="display: block; position: absolute;"><div id="footer"><ol id="'+ options.numericId +'"></ol></div></div>';
                }
                if(options.firstShow) {
                    html += '<span id="'+ options.firstId +'"><a href="#">'+ options.firstText +'</a></span>';
                }
                if(options.prevNext){
                    html += '<span id="'+ options.prevId +'"><a href="#">'+ options.prevText +'</a></span>';
                    html += '<span id="'+ options.nextId +'"><a href="#">'+ options.nextText +'</a></span>';	
                }
                if(options.lastShow) {
                    html += '<span id="'+ options.lastId +'"><a href="#">'+ options.lastText +'</a></span>';
                }
                html += options.controlsAfter;

                if (options.insertAfter) $(obj).after(html);
                else $(obj).before(html);
            };

            if(options.numeric)
            {
				var url = ""+window.location;
				var urlparts = url.split('#');
				var urlparts2 = url.split('/');
				var pageIt = urlparts[1];

				if (urlparts[1]) {
					animate((pageIt-1), true);
				}
    		     
							
                for(var i=0;i<s;i++)
                {        	
						if (document.getElementById('controlsnew'+(i+1))) {
								 $(document.createElement("li"))
								.attr('id',options.numericId + (i+1))
								//.html('<a rel="'+ i +'" href="#"><span>'+ (i+1) +'</span></a>')
								//document.getElementById(\'flashinhoud'+(i+1)+'\').style.display = \'none\';
								
								.html('<a rel="'+ i +'" href="#" onClick="killvideosound('+(i+1)+', '+s+'); document.getElementById(\'blueblock\').innerHTML  = \''+(i+1)+'/'+s+'\';"><span>'+ document.getElementById('controlsnew'+(i+1)).innerHTML +'</span> </a> | ')
								
								//killvideosound("mediabox"+t);
								//('+i+'/'+s+')
								.appendTo($("#"+ options.numericId))
								.click(function(){

									animate($("a",$(this)).attr('rel'),true);
									return false;
								});
						  }
				}
            }

            if(options.prevNext)
            {
				
				var url2 = ""+window.location;
				var urlparts3 = url.split('/');
			
                $("a","#"+options.nextId).click(function(){			
						 
                    animate("next",true); 
					
					tvar = t+1;
					if ((tvar)>s) tvar = 1;
					
						   document.getElementById('blueblock').innerHTML = (tvar)+'/'+s;
					return false;
				
                });
                $("a","#"+options.prevId).click(function(){
                    animate("prev",true); 
					
					tvar = t+1;
					if ((tvar)==0) tvar = s;
					
					    document.getElementById('blueblock').innerHTML = (tvar)+'/'+s;

					return false;
                });
                $("a","#"+options.firstId).click(function(){
                    animate("first",true); return false;
                });
                $("a","#"+options.lastId).click(function(){
                    animate("last",true); return false;
                });
            };
  
            function setCurrent(i)
            {
                i = parseInt(i)+1;
                $("li", "#" + options.numericId).removeClass("current");
                $("li#" + options.numericId + i).addClass("current");
            };

            function adjust()
            {
                if(t>ts) t=0;
                if(t<0) t=ts;
                if(!options.vertical) {
                    ul.css("margin-left",(t*w*-1));
                } else {
                    ul.css("margin-top",(t*h*-1));
                }
                clickable = true;
                if(options.numeric) setCurrent(t);
            };
	

            function animate(dir,clicked)
            {
                				
                if (clickable)
                {
                    clickable = false;
                    var ot = t;
					
                    switch(dir)
                    {
					
                        case "next":
                            t = (ot>=ts) ? (options.continuous ? t+1 : ts) : t+1;
							var urlk = ""+window.location;
							var urlpartsk = urlk.split('/');
							var urlpartsl = urlpartsk[3].split('#');
							if (urlpartsl[0] == "cases") {
							document.getElementById('flashinhoud'+(t)).innerHTML = '';	
							if (document.getElementById('flashinhoud'+(t+1)))  fo[t+1].write('flashinhoud'+(t+1));
							else fo[1].write('flashinhoud1');
							
							//document.getElementById('flashinhoud'+t).style.display = 'none';
							//if (document.getElementById('flashinhoud'+(t+1))) document.getElementById('flashinhoud'+(t+1)).style.display = 'block';
							//else document.getElementById('flashinhoud1').style.display = 'block';
							}
						    if ((t+1)>s) nt=1;
							else nt=(t+1);
							var tempspeed = speed
                            break;
                        case "prev":
                            t = (t<=0) ? (options.continuous ? t-1 : 0) : t-1;
							var urlk = ""+window.location;
							var urlpartsk = urlk.split('/');
							var urlpartsl = urlpartsk[3].split('#');
							if (urlpartsl[0] == "cases") {
							document.getElementById('flashinhoud'+(t+2)).innerHTML = '';	
							if (document.getElementById('flashinhoud'+(t+1)))  fo[t+1].write('flashinhoud'+(t+1));
							
							//document.getElementById('flashinhoud'+(t+2)).style.display = 'none';
							//if (document.getElementById('flashinhoud'+(t+1))) document.getElementById('flashinhoud'+(t+1)).style.display = 'block';
							//else document.getElementById('flashinhoud'+ts).style.display = 'block';
							}
							if ( (t+1)<=0) nt=s;
							else nt= (t+1);
							var tempspeed = speed
                            break;
                        case "first":
                            t = 0;
                            break;
                        case "last":
                            t = ts;
                            break;
                        default:
                            t = parseInt(dir);
							nt=t+1;
							var tempspeed = speed/s;
                            break;
                    };
                   
				  
				   //document.getElementById('footbackjs').style.zIndex = 50;
				   //document.getElementById('footbackjs').style.top = document.getElementById('block1'+nt).offsetHeight + document.getElementById('block1'+nt).offsetTop+'px';
				  if (t<=0) {
					   temp_t=s
				   }
				   else temp_t=t
					if (document.getElementById('block2'))  var block2_height = document.getElementById('block2').offsetHeight;
				   else var block2_height=0;
				  if (reedsuitgevoerd==0) {
				  document.getElementById('footbackjs').style.top = document.getElementById('block1'+nt).offsetHeight + block2_height + 188+'px';
				 // alert (document.getElementById('block1'+nt).offsetTop);
				 // 188 is de height van de header, lelijke hack voor IE7 en lager vanwege de offsetTop die altijd 0 is!
				  reedsuitgevoerd=1;
				  }
				   
				   if (document.getElementById('block1'+temp_t)) {
					   if (document.getElementById('block1'+nt).offsetHeight<document.getElementById('block1'+temp_t).offsetHeight) {
					   $("#footbackjs").animate({width: '883px'}, 1000) 
					   .animate( { top: document.getElementById('block1'+nt).offsetHeight + block2_height + 188+'px' }, speed);
					   } else {
					   $("#footbackjs").animate( { top: document.getElementById('block1'+nt).offsetHeight + block2_height + 188+'px' }, 400);
					   }
				   }
				   
				   $("#blueblock").animate( { opacity: 0 }, 100)
				   .animate( { opacity: 0 }, 400)
				   .animate( { opacity: 1 }, 400);
				   
                   $("#activemenuitem").animate( { borderRightWidth: '1px' }, 400)
				   .animate( { borderRightWidth: '450px' }, 400);
				   
				   
                    var diff = Math.abs(ot-t);
                    var speed = diff*options.tempspeed;
                    if(!options.vertical) {
                        p = (t*w*-1);
                        ul.animate(
                            { marginLeft: p },
                            {
                                queue:false,
                                duration:tempspeed,
                                easing:options.ease,
                                complete:adjust
                            }
                        );
                    } else {
                        p = (t*h*-1);
                        ul.animate(
                            { marginTop: p },
                            {
                                queue:false,
                                duration:tempspeed,
                                easing:options.ease,
                                complete:adjust
                            }
                        );
                    };

                    if(!options.continuous && options.controlsFade)
                    {
                        if(t==0){
                            $("a","#"+options.prevId).fadeOut('slow');
                            $("a","#"+options.firstId).fadeOut('slow');
                        } else if(t==ts){
                            $("a","#"+options.nextId).fadeOut('slow');
                            $("a","#"+options.lastId).fadeOut('slow');
                        } else {
                            $("a","#"+options.prevId).fadeIn('slow');
                            $("a","#"+options.firstId).fadeIn('slow');
                            $("a","#"+options.nextId).fadeIn('slow');
                            $("a","#"+options.lastId).fadeIn('slow');
                        };
                    };

                    if(clicked) clearTimeout(timeout);
                    if(options.auto && dir=="next" && !clicked){;
                        timeout = setTimeout(function(){
                            animate("next",false);
                        },diff*tempspeed+options.pause);
                    };

                };
            };
            // init
            var timeout;
            if(options.auto){;
                timeout = setTimeout(function(){
                    animate("next",false);
                },options.pause);
            };

            if(options.numeric) setCurrent(0);

            if(!options.continuous && options.controlsFade){
                $("a","#"+options.prevId).hide();
                $("a","#"+options.firstId).hide();
            };

        });

    };
})(jQuery);
