// ka_scripts sport-fashion.at: gingebaker 2010

$(document).ready(initSportFashion);

function initSportFashion() {
	initDockMenu();
	initBxSlider();
	initBxSliderFader();
	initDropUpMenu();
	initBottomPxChanger();
}

function isiPhone(){
    return (
        (navigator.platform.indexOf("iPhone") != -1) ||
        (navigator.platform.indexOf("iPod") != -1) ||
		(navigator.platform.indexOf("iPad") != -1)
    );
}


function initBottomPxChanger() {
	bodyheight = $(window).height();
	if(bodyheight < 715) {
		godown = 714 - bodyheight;
		//window.alert(godown);
	}
}



function initDockMenu() {
	if(isiPhone()) {
		$('#appledock_container').attr('id','apple_nodock');
		return false;
	}
	$('#appledock_container').addClass('fisheye');
	$('#appledock_container').Fisheye({
		maxWidth: 50,
		items: 'a',
		itemsText: 'span',
		container: '.dock-container',
		itemWidth: 90,
		proximity: 60,
		alignment : 'left',
		valign: 'bottom',
		halign : 'center'
	});
}



function initBxSliderFader() {
	$('div.bxslider_fadecontainer ul').bxSlider({
		alignment: 'horizontal',        // 'horizontal', 'vertical' - direction in which slides will move
		controls: false,                 // determines if default 'next'/'prev' controls are displayed
		speed: 800,                     // amount of time slide transition lasts (in milliseconds)
		pager: false,                    // determines if a numeric pager is displayed (1 2 3 4...)
		pager_short: false,             // determines if a 'short' numeric pager is displayed (1/4)
		pager_short_separator: ' / ',   // text to be used to separate the short pager
		margin: 0,                      // if 'horizontal', applies a right margin to each slide, if 'vertical' a
		                                // bottom margin is applied. example: margin: 50
		next_text: '&nbsp;&nbsp;&nbsp;',              // text to be displayed for the 'next' control
		next_image: '',                 // image to be used for the 'next' control
		prev_text: '&nbsp;&nbsp;&nbsp;',              // text to be displayed for the 'prev' control
		prev_image: '',                 // image to be used for the 'prev' control
		auto: true,                    // determines if slides will move automatically
		pause: 4000,                    // time between each slide transition (auto mode only) 
		auto_direction: 'next',         // order in which slides will transition (auto mode only)
		auto_hover: true,               // determines if slideshow will pause while mouse is hovering over slideshow
		auto_controls: false,           // determines if 'start'/'stop' controls are displayed (auto mode only)
		ticker: false,                  // determines if slideshow will behave as a constant ticker
		ticker_controls: false,         // determines if 'start'/'stop' ticker controls are displayed (ticker mode only)
		ticker_direction: 'next',       // order in which slides will transition (ticker mode only)
		ticker_hover: true,             // determines if slideshow will pause while mouse is hovering over slideshow
		stop_text: 'stop',              // text to be displayed for the 'stop' control
		start_text: 'start',            // text to be displayed for the 'start' control
		wrapper_class: 'bxslider_wrap'  // class name to be used for the outer wrapper of the slideshow
	});
	
}



function initBxSlider() {
	$('#slidingContent').bxSlider({
		alignment: 'horizontal',        // 'horizontal', 'vertical' - direction in which slides will move
		controls: true,                 // determines if default 'next'/'prev' controls are displayed
		speed: 500,                     // amount of time slide transition lasts (in milliseconds)
		pager: true,                    // determines if a numeric pager is displayed (1 2 3 4...)
		pager_short: false,             // determines if a 'short' numeric pager is displayed (1/4)
		pager_short_separator: ' / ',   // text to be used to separate the short pager
		margin: 0,                      // if 'horizontal', applies a right margin to each slide, if 'vertical' a
		                                // bottom margin is applied. example: margin: 50
		next_text: '&nbsp;&nbsp;&nbsp;',              // text to be displayed for the 'next' control
		next_image: '',                 // image to be used for the 'next' control
		prev_text: '&nbsp;&nbsp;&nbsp;',              // text to be displayed for the 'prev' control
		prev_image: '',                 // image to be used for the 'prev' control
		auto: true,                    // determines if slides will move automatically
		pause: 3500,                    // time between each slide transition (auto mode only) 
		auto_direction: 'next',         // order in which slides will transition (auto mode only)
		auto_hover: true,               // determines if slideshow will pause while mouse is hovering over slideshow
		auto_controls: false,           // determines if 'start'/'stop' controls are displayed (auto mode only)
		ticker: false,                  // determines if slideshow will behave as a constant ticker
		ticker_controls: false,         // determines if 'start'/'stop' ticker controls are displayed (ticker mode only)
		ticker_direction: 'next',       // order in which slides will transition (ticker mode only)
		ticker_hover: true,             // determines if slideshow will pause while mouse is hovering over slideshow
		stop_text: 'stop',              // text to be displayed for the 'stop' control
		start_text: 'start',            // text to be displayed for the 'start' control
		wrapper_class: 'bxslider_wrap'  // class name to be used for the outer wrapper of the slideshow
	});
	// neat little opacity
	$('.bxslider_wrap .prev, .bxslider_wrap .next, .slide_next_inner, .slide_prev_inner').each(function() {
            $(this).hover(function() {
                $(this).stop().animate({ opacity: 0.7 }, 500);
            },
           function() {
               $(this).stop().animate({ opacity: 1.0 }, 500);
           });
     });
	// redirect click function of inner next, prev to the default ones
	$('.slide_next_inner').click(function() {
		$('.bxslider_wrap .next').click();
		return false;
	});
	$('.slide_prev_inner').click(function() {
		$('.bxslider_wrap .prev').click();
		return false;
	});
	// add iphone, ipad swipe functions
	var swipeOptions = 	{ swipe:ka_swipe, threshold:0 }
	$('#slidingContent').swipe( swipeOptions );
	
}


function ka_swipe(event, direction) {
	if(direction == "left") {
		$('.bxslider_wrap .next').click();
		return false;
	} else if(direction == "right") {
		$('.bxslider_wrap .prev').click();
		return false;
	}
}


function initDropUpMenu() {
	$('.secondlevelmenu').each(function() {
		newtop = (0-$(this).height()-4)+'px';
		$(this).css('top',newtop);
	});
	/*$('#mainMenu ul li.expanded').each(function(index) {
		$('ul',this).hide();
		//window.alert("komme rein: "+$('ul',this));
		$(this).bind('mouseenter',function() {
			$('ul',this).fadeIn();
		});
		$(this).bind('mouseleave',function() {
			$('ul',this).fadeOut();
		});
	});*/
}



