// Declare, init
var imgh;
var currentBG = 1;
var showmenu = true;
var menutimer = null;
var menutimer2 = null;
var playVid = false;
var page = 1;
var navtimer = null;
var navtimer2 = null;
var navtimer3 = null;
var cattimer = null;
var sidebarTimer = null;
var simple = 1;
var itemID = 1;
var firstvid = 1;
var cBG2enable = 1;
var postwidth = 130;
var firsttab = 1;
var prevvid;

// Function for getting window sizes for all browsers
    function getSizes() {
        if( typeof( window.innerWidth ) == 'number' ) {
    	//Non-IE
    	myWidth = window.innerWidth;
    	myHeight = window.innerHeight;
    	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    	//IE 6+ in 'standards compliant mode'
    	myWidth = document.documentElement.clientWidth;
    	myHeight = document.documentElement.clientHeight;
    	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    	//IE 4 compatible
    	myWidth = document.body.clientWidth;
    	myHeight = document.body.clientHeight;
    	}
    }

// Get windows sizes on loading, adjust the sizes
    getSizes();
	imgh = myHeight-25;
	imgw = myWidth-138;
	
// On window resize, don't change size directly (too much load), wait for a moment and then resize the containers   	
    var resizeTimer = null;
    jQuery(window).bind("resize",function() {
        resizeTimer = setTimeout(resizeVid, 1000);
		window.clearInterval(navtimer);
		FullScreenBackground("#bg_0","#media-holder2");	
// Run the thumbnail bar function, to calculate the new number of posts to show
		navtimer = setInterval(function(){imgnav2("1")}, 500);
		//cattimer = setInterval(function(){catcontent()}, 500);
    });

// Resize video containers on video page
    function resizeVid() {
    	 imgh = myHeight-25;
    	 getSizes();
         jQuery('#media-holder').css('top:0px');
		 jQuery('#videoholder').css('top:0px');
		 jQuery('#ytplayer_object').height(imgh);
		 jQuery('#videoholder').height(imgh);
		 jQuery('#media-holder').height(imgh);
		 jQuery('.videocomment').height(imgh-250);	  
    }
    
// Load the thumbnail bar for frontpage, new page and videopage    
    function imgnav2(itemID) {
    	
// Get the current window sizes, check if the window is narrow. If so, change width of video container on frontpage
        getSizes();
        
        if (myWidth < 1225) {
        	jQuery("#videoembedcontainer, #content").width("90%");
        	jQuery(".catitem, .catitem img").width(200);
        	jQuery(".catitem img").height(120);
        	jQuery(".catitem").height(153);
        	jQuery("#content, #contentarea").width(650);
        	jQuery("#content, #contentarea").css("margin-left", 140);
        } else {
        	jQuery("#videoembedcontainer").width("100%");
        	jQuery(".catitem, .catitem img").width(250);
        	jQuery(".catitem img").height(150);
        	jQuery(".catitem").height(183);
        	jQuery("#content, #contentarea").width(800);
        	jQuery("#content, #contentarea").css("margin-left", "auto");
        }

// Calculate number of posts possible in the window        
        var numpost = Math.ceil((myWidth) / postwidth);
        
        if (jQuery("#simple").length == 0) {
        	simple = 0;
        }
// Check if we are on the new page        
        var newvid = 1;
        if (jQuery("#new").length == 0) {
        	newvid = 0;
        } 
 
// Load the thumbnail bar depending on the page we are on, after that init the animations and reload the current video. Simple view disables loading video on same page    
        if (category == "" && simple == 0 && newvid == 0) {
        	jQuery("#img-nav").load("/wp-content/themes/VB11/custom.php?num="+numpost+"&page="+page+"&simple="+simple, function() { animations(); changeBG2(itemID);});
        } else if (newvid == 1) { 
        	jQuery("#img-nav").load("/wp-content/themes/VB11/custom.php?num="+numpost+"&page="+page+"&new=1&simple="+simple, function() { animations(); changeBG2(itemID);});
        } else {
        	jQuery("#img-nav").load("/wp-content/themes/VB11/custom.php?num="+numpost+"&page="+page+"&cat="+category+"&simple="+simple, function() { animations(); changeBG2(itemID); });
        }
        window.clearInterval(navtimer);
     
    }   
    
// Init animations at the end of AJAX call, of the thumbnail bar on frontpage and new page, otherwise jQuery animate won't work well   
    function animations() {
    	
// Rollover of thumbnails in thumbnail bar frontpage    	
    	jQuery(".imgroll").animate({opacity: 0.7},"fast");
    	jQuery(".imgroll").hover(function() {
    		jQuery(this).animate({opacity: 1.0},"fast");
    	}, function() {
    		jQuery(this).animate({opacity: 0.7},"fast");
    	});
    	
    	jQuery(".imgroll2").animate({opacity: 0.7},"fast");
    	jQuery(".imgroll2").hover(function() {
    		jQuery(this).animate({opacity: 1.0},"fast");
    	}, function() {
    		jQuery(this).animate({opacity: 0.7},"fast");
    	});
    	
// Thumbnail bar navigation buttons    	
    	jQuery(".img-nav-buttonr").animate({opacity: 0.5},"fast");
    	jQuery(".img-nav-buttonr").hover(function() {
    		jQuery(this).animate({opacity: 1.0},"fast");
    	}, function() {
    		jQuery(this).animate({opacity: 0.5},"fast");
    	});
    	
    	jQuery(".img-nav-buttonr").click(function() {
    		page = page +1;
    		imgnav2(1);
    	});
    	
    	jQuery(".img-nav-buttonl").animate({opacity: 0.5},"fast");
    	jQuery(".img-nav-buttonl").hover(function() {
    		jQuery(this).animate({opacity: 1.0},"fast");
    	}, function() {
    		jQuery(this).animate({opacity: 0.5},"fast");
    	});
    	
    	jQuery(".img-nav-buttonl").click(function() {
    		page = page -1;
    		getSizes();
            
            var numpost = Math.ceil((myWidth) / postwidth);
    		imgnav2(numpost);
    	});
 // Hover effect for thumbnail bar   	
    	jQuery("#img-nav").animate({opacity: 0.8},"fast");
    	jQuery("#img-nav").hover(function() {
    		jQuery(this).animate({opacity: 1.0},"fast");
    	}, function() {
    		jQuery(this).animate({opacity: 0.8},"fast");
    		
    	});	

 // Default is 0, if used, the video on frontpage and new page opens on same page. If is 1 opens the videopage
		if (frontpageEvent == "0") {
			jQuery("#img-nav img").click(function() {
				var bgid2 = jQuery(this).attr("id");
				//navtimer2 = setInterval(function(){changeBG(bgid2, currentBG)}, 500);
				bgid2 = bgid2.replace("bg_", "");
				changeBG(bgid2, currentBG)
				//changeBG(bgid2, currentBG)
			});
			//, function() {
				//window.clearInterval(navtimer2);
			//});
		}
    		
    }

// Used for infinite navigation with arrow keys, so you don't have to click on the next page button
    function changeBG(itemID, oldID) {
    	window.clearInterval(navtimer2);
    	
    	itemID = parseInt(itemID);
// The next video ID is not on the page, go to next page with an AJAX call    	
		if (jQuery("#bg_"+itemID).length == 0 ) {
// Go to next page
			if (itemID > oldID) {
				itemID = oldID;
		        getSizes();
		        
		        var numpost = Math.ceil((myWidth) / postwidth);
// Check if the next video ID is not lower than max num posts. Otherwise it means its the last page
		        if (jQuery("#bg_"+numpost).length != 0 ) {
					page = page + 1;
					itemID = 1;
					imgnav2(itemID);
		        }
// If the video ID is 0, it means we have to go to the previous page
			} else if (itemID == 0) {
				
				if (page == 1) {
					itemID = 1;
				} else {
			        getSizes();
			        
			        var numpost = Math.ceil((myWidth) / postwidth);
					page = page - 1;
					itemID = numpost;
					currentBG = itemID;
					
					imgnav2(itemID);
				}
			}
				
			
		} else {
// The video id is on the same page, so load the normale change function for the video
			changeBG2(itemID, oldID);
		}

// Set current video id		
		currentBG = parseInt(itemID);
		
    }
    
// Change function for frontpage and new page, used to switch video and their data without reloading   
    function changeBG2(itemID, oldID) {
// Check if new view is enabled, otherwise do nothing
    	if (cBG2enable == 1) {
// Reset the timer and get all the data needed for the new video
	    	window.clearInterval(navtimer3);   	
			var vidid = jQuery("#bg_"+itemID).attr("vidid");
			var postid = jQuery("#bg_"+itemID).attr("postid");
			var vidtype = jQuery("#bg_"+itemID).attr("vidtype");
			var title = jQuery("#bg_"+itemID).attr("title");
			var posturl = jQuery("#url_"+itemID).attr("link");
// Check the videosource, get the right embed code			
			if (vidtype == 'vimeo') {
				var embedajax = '<iframe src="http://player.vimeo.com/video/'+vidid+'?title=0&amp;byline=0&amp;portrait=0&hd=1&autoplay='+autoplayfront+'" width="600" height="335" frameborder="0"></iframe>';
			} else if (vidtype == 'youtube') {
				var embedajax = '<iframe width="600" height="335" src="http://www.youtube.com/embed/'+vidid+'?rel=0&amp;hd=1&amp;autoplay='+autoplayfront+'&amp;wmode=opaque" frameborder="0" allowfullscreen></iframe>';
			}
// Set the other information of the video			
			jQuery("#videoembed").html(embedajax);
			jQuery("#facebook").html('<iframe src="http://www.facebook.com/plugins/like.php?app_id=191141250924045&amp;href='+posturl+'&amp;send=false&amp;layout=button_count&amp;width=100&amp;show_faces=true&amp;action=like&amp;colorscheme=light&amp;font&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:21px;" allowTransparency="true"></iframe>');
			jQuery("#titel").html(title);
// Set colour for background of the video on frontpage
			jQuery("#nav2").css("background-color",jQuery("#bg_"+itemID).attr("category"));
			jQuery("#readmore a").attr("href",posturl);
		
// Making the rating plugin dynamic			
			if (firstvid == 1) {
				jQuery("#post-ratings").attr("id", "post-ratings-"+postid);
				jQuery("#post-ratings-loading").attr("id", "post-ratings-"+postid+"-loading");
				
// Output the rating stars for the first video				
				for (var i=1;i<6;i++) {
					jQuery("#rating_"+i).attr("id", "rating_"+postid+"_"+i);
				}
// Ratings after first video
			} else {

// Change the ID in the rating stars to the new one
				jQuery("#post-ratings-"+prevvid).attr("id", "post-ratings-"+postid);
				//alert("#post-ratings-"+prevvid);
				jQuery("#post-ratings-"+prevvid+"-loading").attr("id", "post-ratings-"+postid+"-loading");
// Output the rating stars after first video
				for (var i=1;i<6;i++) {
					jQuery("#rating_"+prevvid+"_"+i).attr("id", "rating_"+postid+"_"+i);
				}	
				
			}

			prevvid = postid;
			
			firstvid = 0;
// Load the post view function, not directly 			
			navtimer3 = setInterval(function(){countviews(postid)}, 20000);
			
// Fade the thumbnail of the old video out, and fade the new one in			
			jQuery("#bg_"+itemID).animate({opacity: 1.0},"fast");
			jQuery("#bg_"+oldID).animate({opacity: 0.8},"fast");
		
    	} 
    	
    }
    
    
// AJAX call for post views on frontpage and new page, not for classic view
    function countviews(postid) {
    	jQuery("#loadviews").load("/wp-content/themes/VB11/views.php?postviews_id="+postid);
    	window.clearInterval(navtimer3);
    }

    
// Hide GUI function for video page
    function hideGUI() {

        jQuery("#logo img").animate({
			width: '156px'
        },"slow");
// After animation of the menu, set showmenu to false
  		jQuery("#menu").animate({
		    opacity: 0.0,
		    left: '-=150px',
		    filter: ''
		
		  }, "slow", function() {
			  jQuery('#head-title').animate({opacity: '0.0'},"fast");
			  showmenu = false;
		  });
		jQuery("#nav, #videoinfo").animate({
		    opacity: 0.0
		  }, "fast", function() {
			  jQuery("#nav, #videoinfo").hide();
		  });
		 getSizes();
		 imgh = myHeight-25;

		 jQuery('#videoholder').height(imgh);
		 jQuery('#ytplayer_object').height(imgh);
		 jQuery('#media-holder').height(imgh);	
    };

// Show GUI function for video page
    function showGUI() {
        jQuery("#logo img").animate({
			width: '312'
        },"slow");
// After animation of the menu, set showmenu to true
  		jQuery("#menu").animate({
		    opacity: 1.0,
		    left: '-1',
		    filter: ''
		  }, "slow", function() {
			  showmenu = true;
		  });
  		jQuery("#nav, #videoinfo").show();
		jQuery("#nav, #videoinfo").animate({
		    opacity: 1.0,
		    filter: ''
		  }, "fast", function() {
		   // showGUIvid();
		  });	

		 
    };
    
// Deprecated function for calculating height of the playing video
    function showGUIvid() {
    	 getSizes();
		
		 
		 jQuery('#videoholder').height(imgh);
		 jQuery('#media-holder').height(imgh);
		 jQuery('#ytplayer_object').height(imgh);    
		 jQuery('#head-title').animate({opacity: "0.7"},"fast");
    }
    
    
// Deprecated function, for calculating posts (depending on screen size) on category pages
    function catcontent() {
    	getSizes();
    	
    	var catpost = Math.floor((myHeight-300) / 180);
    	catpost = catpost * 3;
    	
    }
    
// Switch function for the sidebar on frontpage
    function rightcolSwitch(sID) {
    	sID = parseInt(sID);
		jQuery("#sprite_"+firsttab+"_a").attr("id","sprite_"+firsttab);
		jQuery("#sprite_"+sID).attr("id","sprite_"+sID+"_a");
		jQuery("#rightcol1").load("/wp-content/themes/VB11/custom-right.php?f="+sID);
		firsttab = sID;
    }
// Switch timer for sidebar
    function rightcolTimer() {
    	if (jQuery("#sprite_"+(firsttab+1)).length == 0 ) {
			nsID = 1;
		} else {
			nsID = firsttab +1;
		}
    	rightcolSwitch(nsID);
    }
    

    
// Everything is loaded, run these functions
$imgloaded = 0;
$imgloadert = null; 

    jQuery(document).ready(function() {
    	
    	$preloader = jQuery("#preloader");
    	$imgloadert = setTimeout(function(){ if($imgloaded==0){  
    	
    	var $this=jQuery(".bgimg");		
			FullScreenBackground($this,"#media-holder2");					
			$preloader.fadeOut("fast");
			jQuery(".bgimg").fadeIn("slow", function () {  $imgloaded = 1; });			
    		
    	} },3000);
				
		jQuery(".bgimg").load(function() {		

			var $this=jQuery(this);		
			FullScreenBackground($this,"#media-holder2");					
			$preloader.fadeOut("fast");
			jQuery(".bgimg").fadeIn("slow", function () {  $imgloaded = 1; });							
		});
		
	
    	
    	
// Init all functions for dimensions
    	imgnav2("1");
    	catcontent();
    	jQuery('.videocomment').height(imgh-250);	
		
		
// ratings button
		jQuery(".rating").mouseover(function(){
			var ratid = jQuery(".post-ratings").attr("id");
			ratid = ratid.replace("post-ratings-","")
			var ratnum = jQuery(this).attr("id");
			ratnum = ratnum.replace("rating_"+ratid+"_","");
			
			current_rating(ratid, ratnum, ratnum+' Stars');
			
		});
		
// Loading new videos since last visit
		jQuery("#numnew").load("/wp-content/themes/VB11/custom-new.php");



// When clicked on a tab, load the right data in the right col
		jQuery("#sprite_4").click(function(){
			rightcolSwitch(4);
		});
		jQuery("#sprite_1").click(function(){
			rightcolSwitch(1);
		});
		jQuery("#sprite_3").click(function(){
			rightcolSwitch(3);
		});
		jQuery("#sprite_2").click(function(){
			rightcolSwitch(2);	
		});
		
// Loading sidebar on frontpage	
		rightcolSwitch(firsttab);	
		
// Timer for sidebar, switches every now and then. Stops on hover sidebar
		jQuery("#rightcol").hover(function(){
			window.clearInterval(sidebarTimer);
		}, function(){ 
			sidebarTimer = setInterval(function(){ rightcolTimer() }, 20000);
		});
		
		sidebarTimer = setInterval(function(){ rightcolTimer() }, 20000);
		
		
// Navigate videos with keyboard
		jQuery(document).keydown(function(e){
		    if (e.keyCode == 37) { 
				bgid2 = currentBG - 1;
				changeBG(bgid2, currentBG)
		    }
		    if (e.keyCode == 39) { 
		    	bgid2 = currentBG + 1;
				changeBG(bgid2, currentBG)
		    }
		});
    	
    	
// Setting dimensions for videos
    	jQuery(".content_frontpage_item").css({opacity: 0.8});
   	 	jQuery('#videoholder').height(imgh);
		jQuery('#media-holder').height(imgh);
		
		jQuery('#ytplayer_object').height(imgh);
		jQuery('#head-title').width(imgw);
		jQuery("#head-title").css({opacity: 0.7});
		
// Show or hide GUI when viewing video page
		jQuery("#logo, #menu, #content").hover(function() {
			window.clearTimeout(menutimer);
		    menutimer = null;
			if(showmenu == false) {
				if(playVid == true) {
					showGUI();
				}
			}
		}, function(){
			if(showmenu == true) {
				if(playVid == true) {
					menutimer = setTimeout(hideGUI, 1000);
				}
			}
		});
		
// Show or hide GUI when viewing video page, this time for control bar
		jQuery("#controlbar").hover(function() {
			window.clearTimeout(menutimer2);
		    menutimer2 = null;
			if(showmenu == false) {
				if(playVid == true) {
					showGUI();
				}
			}
			if(showmenu == false) {
				if(playVid == true) {
					menutimer2 = setTimeout(hideGUI, 5000);
				}
			}
		}, function(){
			if(showmenu == true) {
				if(playVid == true) {
					menutimer2 = setTimeout(hideGUI, 1000);
				}
			}
		});
		
		
// Showing whole background when hovering over photo by link
		jQuery("#photo-credit").css({opacity: 0.5});
		
		jQuery("#photo-credit").hover(function() {
			jQuery(".contentarea, #nav2, #content, #contentarea, #nav3, #rightcol, .rightcol2, .rightcol3").animate({opacity: 0.0},"fast")
			jQuery("#photo-credit").animate({opacity: 0.7},"fast")
			hideGUI();
		},function(){
			jQuery(".contentarea, #nav2, #content, #contentarea, #nav3, #rightcol, .rightcol2, .rightcol3").animate({opacity: 1.0},"fast")
			jQuery("#photo-credit").animate({opacity: 0.5},"fast")
			showGUI();
		});
		
		
// Hover effect for category item
		jQuery(".catitem").animate({opacity: 0.8},"fast")
		jQuery(".catitem").hover(function() {
			jQuery(this).animate({opacity: 1.0},"fast")
		},function(){
			jQuery(this).animate({opacity: 0.8},"fast")
		});
		
		
// Sorting category post, by sorting type
		jQuery("#sorting").change(function() {
			var sorting = jQuery(this).val();
			if (sorting == "title") {
				sorting = "?ordervideo=title&orderdirvideo=";
			} else if (sorting == "date") {
				sorting = "?ordervideo=date&orderdirvideo=";
			} else if (sorting == "views") {
				sorting = "?v_sortby=views&v_orderby=";
			} else if (sorting == "rating") {
				sorting = "?r_sortby=highest_rated&r_orderby=";
			} else {
				sorting = "?sortby=date&orderby=";
			}
			window.location = window.location.pathname+sorting+jQuery("#sortingorder").val();   
		});
		
// Sorting category post, by sorting order		
		jQuery("#sortingorder").change(function() {
			var sortingorder = jQuery(this).val();
			if (sortingorder == "asc") {
				sortingorder = "asc";
			} else {
				sortingorder = "desc";
			}
			var sorting = jQuery("#sorting").val();
			if (sorting == "title") {
				sorting = "?ordervideo=title&orderdirvideo=";
			} else if (sorting == "date") {
				sorting = "?ordervideo=date&orderdirvideo=";
			} else if (sorting == "views") {
				sorting = "?v_sortby=views&v_orderby=";
			} else if (sorting == "rating") {
				sorting = "?r_sortby=highest_rated&r_orderby=";
			} else {
				sorting = "?sortby=date&orderby=";
			}
			window.location = window.location.pathname+sorting+sortingorder;   
		});
		
		
// Options form, getting the data		
		jQuery("#save").click(function() { 
			var datastring = '';
			var firststring = 0;
			if (jQuery("input#autoplay1").is(':checked')) {
				if (firststring == 0 ) {
					firststring = 1;
				} else {
					datastring += "&";
				}
				datastring += 'autoplay1=autoplay1';
			} 
			if (jQuery("input#autoplay2").is(':checked')) {
				if (firststring == 0 ) {
					firststring = 1;
				} else {
					datastring += "&";
				}
				datastring += 'autoplay2=autoplay2';
			} 
			if (jQuery("input#autoplay3").is(':checked')) {
				if (firststring == 0 ) {
					firststring = 1;
				} else {
					datastring += "&";
				}
				datastring += 'autoplay3=autoplay3';
			}
			if (jQuery("input#autoplay4").is(':checked')) {
				if (firststring == 0 ) {
					firststring = 1;
				} else {
					datastring += "&";
				}
				datastring += 'autoplay4=autoplay4';
			}
			if (jQuery("input#autoplay5").is(':checked')) {
				if (firststring == 0 ) {
					firststring = 1;
				} else {
					datastring += "&";
				}
				datastring += 'autoplay5=autoplay5';
			}
			if (jQuery("input#autoplay6").is(':checked')) {
				if (firststring == 0 ) {
					firststring = 1;
				} else {
					datastring += "&";
				}
				datastring += 'autoplay6=autoplay6';
			}

// Categories
			if (jQuery("input#kite").is(':checked')) {
				if (firststring == 0 ) {
					firststring = 1;
				} else {
					datastring += "&";
				}
				datastring += 'kite=kite';
			} 
			if (jQuery("input#other").is(':checked')) {
				if (firststring == 0 ) {
					firststring = 1;
				} else {
					datastring += "&";
				}
				datastring += 'other=other';
			} 
			if (jQuery("input#skate").is(':checked')) {
				if (firststring == 0 ) {
					firststring = 1;
				} else {
					datastring += "&";
				}
				datastring += 'skate=skate';
			} 
			if (jQuery("input#snow").is(':checked')) {
				if (firststring == 0 ) {
					firststring = 1;
				} else {
					datastring += "&";
				}
				datastring += 'snow=snow';
			} 
			if (jQuery("input#surf").is(':checked')) {
				if (firststring == 0 ) {
					firststring = 1;
				} else {
					datastring += "&";
				}
				datastring += 'surf=surf';
			}
			if (jQuery("input#wake").is(':checked')) {
				if (firststring == 0 ) {
					firststring = 1;
				} else {
					datastring += "&";
				}
				datastring += 'wake=wake';
			} 
			if (jQuery("input#wind").is(':checked')) {
				if (firststring == 0 ) {
					firststring = 1;
				} else {
					datastring += "&";
				}
				datastring += 'wind=wind';
			}
			
// Posting options with AJAX
		    jQuery.ajax({
		        type: "POST",
		        url: "/wp-content/themes/VB11/custom-options.php",
		        data: datastring,
		        success: function(data) {
		          jQuery("#message").html(data);
		        }
		      });
		      return false;
		});
		

		
    }); 
    
    		function FullScreenBackground(theItem,theContainer){
			    var winWidth=jQuery(window).width();
			    var winHeight=jQuery(window).height();
			    var imageWidth=jQuery(theItem).width();
			    var imageHeight=jQuery(theItem).height();			    
			    var picHeight = imageHeight / imageWidth;
			    var picWidth = imageWidth / imageHeight;
			    
			    if ((winHeight / winWidth) < picHeight) {
			        jQuery(theItem).css("width",winWidth);
			        jQuery(theItem).css("height",picHeight*winWidth);
			    } else {
			        jQuery(theItem).css("height",winHeight);
			        jQuery(theItem).css("width",picWidth*winHeight);
			    };
			    jQuery(theContainer).css("width",winWidth);
			    jQuery(theContainer).css("height",winHeight);
			    jQuery(theItem).css("margin-left",(winWidth- jQuery(theItem).width())/2);
			    jQuery(theItem).css("margin-top",(winHeight- jQuery(theItem).height())/2);
		} 
		
	
		

/*
// Fullscreen BG
(function($) {
    var containerObj, center = false;

    // plugin definition
    $.fn.ezBgResize = function(center) {
        center = center || false;
    
        //console.log(center);
        // First position object
        containerObj = this;

        containerObj.css("visibility","hidden");

        $("body").css({
            "overflow-x":"hidden"
        });

        $(window).load(function() {
            resizeImage();
        });

        $(window).bind("resize",function() {
            resizeImage();
        });

    };

    function resizeImage() {
        $("body").css({
            "overflow-x":"hidden"
        });

        containerObj.css({
            "position":"fixed",
            "top":"-0px",
            "left":"0px",
            "z-index":"-1",
            "overflow":"hidden",
            "width":getWindowWidth() + "px",
            "height":getWindowHeight() + "px"
        });

        // Resize the img object to the proper ratio of the window.
        var iw = containerObj.children('img').width();
        var ih = containerObj.children('img').height();
        
        containerObj.breedte = 999;
        
        if ($(window).width() > $(window).height()) {
            //console.log(iw, ih);
            if (iw > ih) {
                var fRatio = iw/ih;
                containerObj.children('img').css("width",$(window).width() + "px");
                containerObj.children('img').css("height",Math.round($(window).width() * (1/fRatio)));

                var newIh = Math.round($(window).width() * (1/fRatio));

                if(newIh < $(window).height()) {
                    var fRatio = ih/iw;
                    containerObj.children('img').css("height",$(window).height());
                    containerObj.children('img').css("width",Math.round($(window).height() * (1/fRatio)));
                }
            } else {
                var fRatio = ih/iw;
                containerObj.children('img').css("height",$(window).height());
                containerObj.children('img').css("width",Math.round($(window).height() * (1/fRatio)));
            }
        } else {
            var fRatio = ih/iw;
            containerObj.children('img').css("height",$(window).height());
            containerObj.children('img').css("width",Math.round($(window).height() * (1/fRatio)));
        }
        
        containerObj.css("visibility","visible");

        // Center BG Image
        if (center) {
            containerObj.children('img').css("position","relative");

            if (containerObj.children('img').width() > containerObj.width()) {
                var wDiff = (containerObj.children('img').width() - containerObj.width()) / 2;
                containerObj.children('img').css("left", "-" + wDiff + "px");
            }
        }
    }

    // Dependable function to get Window Height
    function getWindowHeight() {
        var windowHeight = 0;
        if (typeof(window.innerHeight) == 'number') {
            windowHeight = window.innerHeight;
        }
        else {
            if (document.documentElement && document.documentElement.clientHeight) {
                windowHeight = document.documentElement.clientHeight;
            }
            else {
                if (document.body && document.body.clientHeight) {
                    windowHeight = document.body.clientHeight;
                }
            }
        }
        return windowHeight;
    };

    // Dependable function to get Window Width
    function getWindowWidth() {
        var windowWidth = 0;
        if (typeof(window.innerWidth) == 'number') {
            windowWidth = window.innerWidth;
        }
        else {
            if (document.documentElement && document.documentElement.clientWidth) {
                windowWidth = document.documentElement.clientWidth;
            }
            else {
                if (document.body && document.body.clientWidth) {
                    windowWidth = document.body.clientWidth;
                }
            }
        }
        return windowWidth;
    };
})(jQuery); */
