/*
/*	Dynamic design functions and onLoad events
/*	----------------------------------------------------------------------
/* 	Creates added dynamic functions and initializes loading.
*/


// ======================================================================
//
//	On document ready functions
//
// ======================================================================

$(document).ready(function() {

$('#feedback-container').feedback();
       $(".iframe").fancybox({
           'width': '50%',
           'height': '70%',
           'type': 'iframe'
       });

	// initialise main-menu (jQuery superfish plug-in)
	// -------------------------------------------------------------------


	// Slide down top content (topReveal)
	// -------------------------------------------------------------------
	$('.topReveal').click( function() {
		$('#ContentPanel').slideToggle(800);	// show/hide the content area
		$.scrollTo('#ContentPanel');
		return false;
	});





	// input lable replacement
	// -------------------------------------------------------------------
	$("label.overlabel").overlabel();

	// initialize anchor tag scrolling effect (scrollTo)
	// -------------------------------------------------------------------
	$.localScroll();

	// apply custom search input functions
	// -------------------------------------------------------------------
	searchInputEffect();

	// apply custom button styles
	// -------------------------------------------------------------------
	buttonStyles();

	// CSS Rounded Corners (not for IE)
	// -------------------------------------------------------------------
	if (!jQuery.browser.msie) {
		$("a.img, div.img, .textInput, input[type='text'], input[type='password'], textarea").addClass('rounded');	// items to add rounded class
		roundCorners(); // execute it!
	}

        $(window).scroll(function(){
    ribbonPosition()
    });
ribbonPosition();
$("img.reflect").reflect({/* Put custom options here */});
	$('#slider_area').cycle({
		fx:     'scrollHorz',
		easing: 'backout',
		timeout: 5110,
		pager:  '#numbers',
		pagerAnchorBuilder: function(idx) {
			return '<li><a href="#" title="">' + (idx+1) + '</a></li>';
		}
	});
});




// ======================================================================
//
//	Design functions
//
// ======================================================================



// Modal after load functions
// -------------------------------------------------------------------

function modalStart() {
	// updated styles
	$('#fancy_inner').addClass('rounded');
	roundCorners();
}





// Search input - custom effects for mouse over and focus.
// -------------------------------------------------------------------

function searchInputEffect() {

	var	searchFocus = false,
		searchHover = false,
		searchCtnr = $('#Search');
		searchInput = $('#SearchInput'),
		searchSubmit = $('#SearchSubmit');
	// Search input - mouse events
	searchCtnr.hover(
		function () {	// mouseover
			if (!searchFocus) $(this).addClass('searchHover');
			searchHover = true; },
		function () {	// mouseout
			if (!searchFocus) $(this).removeClass('searchHover');
			searchHover = false;
	}).mousedown( function() {
		if (!searchFocus) $(this).removeClass('searchHover').addClass('searchActive');
	}).mouseup( function() {
		searchInput.focus();
		searchSubmit.show();
		searchFocus = true;
	});
	// set focus/blur events
	searchInput.blur( function() {
		if (!searchHover) {
			searchCtnr.removeClass('searchActive');
			searchSubmit.hide();
			searchFocus = false;
		}
	});
}



// button styling function
// -------------------------------------------------------------------

function buttonStyles() {
	// Button styles

	// This will style buttons to match the theme. If you don't want a button
	// styled, give it the class "noStyle" and it will be skipped.
	//$("button:not(:has(span),.noStyle), input[type='submit']:not(.noStyle), input[type='button']:not(.noStyle)").each(function(){
	$("button .btn, input[type='submit'] .btn, input[type='button'] .btn").each(function(){
		var	b = $(this),
			tt = b.html() || b.val();

		// convert submit inputs into buttons
		if (!b.html()) {
			b = ($(this).attr('type') == 'submit') ? $('<button type="submit">') : $('<button>');
			b.insertAfter(this).addClass(this.className).attr('id',this.id);
			$(this).remove();	// remove input
		}
		b.text('').addClass('btn').append($('<span>').html(tt));	// rebuilds the button
	});

	// Get all styled buttons
	var styledButtons = $('.btn');

	// Fix minor problem with Mozilla and WebKit rendering (can also be done adding this to CSS,
	// button::-moz-focus-inner {border: none;}
	// @media screen and (-webkit-min-device-pixel-ratio:0) { button span {margin-top: -1px;} }
	if (jQuery.browser.mozilla || jQuery.browser.webkit) {
		styledButtons.children("span").css("margin-top", "-1px");
	}

	// Button hover class (IE 6 needs this)
	styledButtons.hover(
		function(){ $(this).addClass('submitBtnHover'); },		// mouseover
		function(){ $(this).removeClass('submitBtnHover'); }	// mouseout
	);
}

// Rounded corner styles
// -------------------------------------------------------------------

function roundCorners() {
	$('.rounded, .ui-corner-all').css({
		'-moz-border-radius': '4px',
		'-webkit-border-radius': '4px',
		'border-radius': '4px'
	});
}

// Font replacement
// -------------------------------------------------------------------




    function ribbonPosition(){
    var t=$(window).scrollTop();
    var h=$(window).height();
    var offset=$(window).height()/25;
    var zoneSize=$(window).height()/3;
    var zoneOne=t+zoneSize+offset;
    var zoneTwo=t+zoneSize*2-offset;
    $(".ribbon .wrapAround").each(function(){
        var obj=$(this);
        var objH=obj.height();
        var offset=obj.offset();
        if(offset.top+objH<=zoneOne){
            $(this).css('background-position','0 0')
            }else if(offset.top>=zoneTwo){
            $(this).css('background-position','0 -104px')
            }else{
            $(this).css('background-position','0 -52px')
            }
        })
}
