/* - - - - - - - - - - - - - - - - - - - - -
Title: 	Brightworks
Author: Brightworks, http://www.brightworks.nl
URL: 	/css/screen.css
- - - - - - - - - - - - - - - - - - - - - */

$(function(){
	
	// rating
	
	/*$('#detail_rate').raty({
		starOn: 'rate_on.gif',
		starOff: 'rate_off.gif',
		size:11,
  		// Ajax event ...
  		click: function(score, evt) {
    		alert('ID: ' + this.attr('id') + '\nscore: ' + score + '\nevent: ' + evt);
  		}
	});*/
	
	// resize bg on resize	
	$(window).resize(function() {
		$('#bgimg').fullscreen();
		if ($(window).width() > ($('#site-main').outerWidth() + ($('#site-adv').width()*2))) {
			$('#site-container').removeClass('no-ad');
		} else {
			$('#site-container').addClass('no-ad');
		}
	});
	$(window).resize();
	
	// clear default
	$('input.clear-default').clearDefault();



// ONDERTSAANDE REGELS KUNNEN WEG, ALS ALLE COURSELLEN MET BOLLETJES WERKEN!!!!
    jQuery('.carousel').jcarousel({
        scroll: 3
    });
    jQuery('ul.carousel-sng').jcarousel({
        scroll: 1
    });	
/////////    
    
    
	// login
	/*$('a#login-button').live('click', function() {
		var button = $(this);
		var dropdown = 'div#login-dropdown';
		// show submenu
		button.addClass('hover');
		$(dropdown).css({
			position: 'absolute',
			top: button.offset().top + button.outerHeight() + 'px',
			left: button.offset().left - $(dropdown).outerWidth(true) + button.outerWidth(false) + 'px',
			zIndex: 1000
		}).stop(false, true).slideDown(300);

		// dropdown mouseleave
		$(dropdown).mouseleave(function(ev){
			if (!($(ev.relatedTarget).is('a#login-button'))){
				$(dropdown).slideUp(200, function(){
					button.removeClass('hover');
				});
			}
		});
		// button mouseleave
		button.mouseleave(function(ev){
			if (!($(ev.relatedTarget).is(dropdown) || $(ev.relatedTarget).parents().is(dropdown))){
				$(dropdown).slideUp(200, function(){
					button.removeClass('hover');
				});
			}
		});
		return false;
	});

	// rtv dropdwon
	$('a#rtv-button').live('click', function() {
		var button = $(this);
		var dropdown = 'div#rtv-dropdown';
		// show submenu
		button.addClass('hover');
		$(dropdown).css({
			position: 'absolute',
			top: button.offset().top + button.outerHeight() + 'px',
			left: button.offset().left - $(dropdown).outerWidth(true) + button.outerWidth(false) + 'px',
			zIndex: 1000
		}).stop(false, true).slideDown(300);

		// dropdown mouseleave
		$(dropdown).mouseleave(function(ev){
			if (!($(ev.relatedTarget).is('a#rtv-button'))){
				$(dropdown).slideUp(200, function(){
					button.removeClass('hover');
				});
			}
		});
		// button mouseleave
		button.mouseleave(function(ev){
			if (!($(ev.relatedTarget).is(dropdown) || $(ev.relatedTarget).parents().is(dropdown))){
				$(dropdown).slideUp(200, function(){
					button.removeClass('hover');
				});
			}
		});
		return false;
	});*/

	//Dropdown

		$('ul#nav li.dropdown a').live('mouseover', function() {
		var button = $(this);
		var dropdown = button.next('div.dropdown-menu');
		// show submenu
		button.addClass('hover');
		$(dropdown).css({
			position: 'absolute',
			top: button.offset().top + button.outerHeight() + 'px',
			left: button.offset().left - $(dropdown).outerWidth(true) + button.outerWidth(false) + 2 + 'px',
			zIndex: 1000
		}).stop(false, true).slideDown(100);

		// dropdown mouseleave
		$(dropdown).mouseleave(function(ev){
			if (!($(ev.relatedTarget).is(button))){
				$(dropdown).slideUp(50, function(){
					button.removeClass('hover');
				});
			}
		});
		// button mouseleave
		button.mouseleave(function(ev){
			if (!($(ev.relatedTarget).is(dropdown) || $(ev.relatedTarget).parents().is(dropdown))){
				$(dropdown).slideUp(50, function(){
					button.removeClass('hover');
				});
			}
		});
		return false;
	});
	
	
	
// TABS
	//When page loads...
	$(".tab-content").hide(); //Hide all content
	if ($("ul.tabs li.active").size() == 0) {
		$("ul.tabs li:first").addClass("active"); //Activate first tab
	}
	$($("ul.tabs li.active").find("a").attr("href")).show();
	//$(".tab-content:first").show(); //Show first tab content

	//On Click Event
	$("ul.tabs li").not('.no-tab').click(function() {

		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab-content").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active ID content
		return false;
	});	
	
	
	// ie6 png fix
	//$(document).pngFix(); 
});

(function($){
    $.fn.extend({
		fullscreen: function(){
			return this.each(function() {
				var winWidth=$(window).width();
				var winHeight=$(window).height();
				var imageWidth=$(this).width();
				var imageHeight=$(this).height();
				var picHeight = imageHeight / imageWidth;
				var picWidth = imageWidth / imageHeight;
				if ((winHeight / winWidth) < picHeight) {
					$(this).css("width",winWidth);
					$(this).css("height",picHeight*winWidth);
				} else {
					$(this).css("height",winHeight);
					$(this).css("width",picWidth*winHeight);
				};
				$(this).css("margin-left",winWidth / 2 - $(this).width() / 2);
				$(this).css("margin-top",winHeight / 2 - $(this).height() / 2);	
			});	
		},
        clearDefault: function(){
            return this.each(function(){
                var default_value = $(this).val();
                $(this).focus(function(){
                    if ($(this).val() == default_value) 
                        $(this).val("");
                });
                $(this).blur(function(){
                    if ($(this).val() == "") 
                        $(this).val(default_value);
                });
            });
        }
    }); 
})(jQuery);
