//no-confict mode
var $jQ = jQuery.noConflict();

//------- FUNCTION POPUP WINES -------
function balloon (e) {

	var popID = e;
    var popWidth = 500;

    //Fade in the Popup and add close button
    $jQ('#' + popID).fadeIn().css({ 'width': (popWidth+'px') }).prepend('<a href="#" class="close"></a>');

    //Define margin for center alignment (vertical   horizontal) - we add 80px to the height/width to accomodate for the padding  and border width defined in the css
    var popMargTop = ($jQ('#' + popID).height() + 80) / 2;
    var popMargLeft = ($jQ('#' + popID).width() + 80) / 2;

    //Apply Margin to Popup
    $jQ('#' + popID).css({
        'margin-top' : -popMargTop,
        'margin-left' : -popMargLeft
    });

    //Fade in Background
    $jQ('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
    $jQ('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies 

    return false;

}


//start functions
$jQ(document).ready(function() {
	
	//------- SLIDESHOW -------
    $jQ('.slideshow').cycle({
		fx: 'fade'
 	});
	
	$jQ('.slideshow-history').cycle({
	}).cycle('pause');
	$jQ('#play-pause').click(function() {
	$jQ('.slideshow-history').cycle('toggle');
	});
	
	//------- GALLERY WINES-------
	$jQ(window).load(function() {
		$jQ("div#makeMeScrollable").smoothDivScroll();
	});
	
	
	
	//------- MOUSE EFFECTS GALLERY WINES-------
	$jQ("div#makeMeScrollable img").clearQueue();
	$jQ("div#makeMeScrollable img").animate({"opacity": "0.6"}, 200);
	$jQ("div#makeMeScrollable img").mouseover(function(){
	$jQ(this).clearQueue();
	$jQ(this).animate({"opacity": "1"}, 200);
	});
	$jQ("div#makeMeScrollable img").mouseout(function(){
	$jQ(this).clearQueue();
	$jQ(this).animate({"opacity": "0.6"}, 200);
	});
	
	
	
	//------- POPUP WINES -------
	//When you click on a link with class of poplight and the href starts with a # 
	$jQ('a.poplight[href^=#]').click(function() {
	var id_wine = $jQ(this).attr('rel');
   	balloon(id_wine);
	});
	
	
	
	//Close Popups and Fade Layer
	$jQ('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
    $jQ('#fade , .popup_block').fadeOut(function() {
        $jQ('#fade, a.close').remove();  //fade them both out
    });
    return false;
	});
	
	
	
	//------- CALENDAR FORM AGRITURISMO -------
	$jQ( ".datepicker").datepicker({ showAnim: 'slideDown' });
	$jQ(".datepicker-it").datepicker({ showAnim: 'slideDown' }, $jQ.datepicker.regional['it']);
	$jQ(".datepicker-de").datepicker({ showAnim: 'slideDown' }, $jQ.datepicker.regional['de']);
	
	
	//------- INDEX MAP -------
	$jQ('#map-company .button-balloon').toggle(
    function()
    {

        //If user clicked on a link which is already displayed, do nothing.
        if (($jQ('#'+$jQ(this).attr('id')+'-balloon')).hasClass('selected')) 
            return;
            
        //hide all the divs.
        $jQ('div.balloon-info')
            .hide()
            .removeClass('selected');

        //show the selected div.
		$jQ('#'+$jQ(this).attr('id')+'-balloon').fadeIn('slow');
		
            	},
            function() { 
        	$jQ('#'+$jQ(this).attr('id')+'-balloon').fadeOut('slow');
        });
	
	$jQ(".button-balloon").mouseover(function () {
    	$jQ(this).css("background-position","0 -60px"); 
    });
    $jQ(".button-balloon").mouseout(function () {
      $jQ(this).css("background-position","0 0px"); 
    });
	
	$jQ('#map-company').click(function() {
    $jQ('div.balloon-info').fadeOut();
	});
	
	//------- CSS3 PIE -------
	if (window.PIE) {
        $jQ('#news-index .slideshow, .post-dashboard, .post-dashboard a, .post-dashboard h3, #back-news, #post span.date-post, #post .content-post, #sidebar #search #s, #sidebar #search #searchsubmit, #other-links a,#play-pause').each(function() {
            PIE.attach(this);
        });
    }
	
	
	
});
//end functions
