var interval = null;
var startedSlide = false;
var slideBack = false;
var binded = false;
/*lightbox */
function stopSlideshow() {
	if(startedSlide) {
            startedSlide = false;
            clearInterval( interval );
	    interval = null;
	    slideBack = false;
	    $( '#slideshow img' ).attr('src', 'images/slideshowOn.png');
          }
}
$( function() {
    $( '#galery' ).css( 'position', 'relative' ).append( '<a href="#" id="startSlideshow" style="top: 20px; right: 0px; z-index: 4; position: absolute; border: 0px solid;"><img src="images/slideshowOn.png" style="border: 0px solid" alt="" /></a>' );
    $('#startSlideshow').click( function() {
	stopSlideshow();
        $( $( '#galery a[rel=lightbox[gallery]]' ).get(0) ).click();
        setTimeout( function() {

	    

            $('#slideshow').click();
            
            
        }, 500 )
        return false;
    } );
    $('[rel=lightbox], [rel=lightbox[gallery]],.fullNews .img .min').click( function() {
	  stopSlideshow();
	  setTimeout( function() { if(!binded) { $('#slideshow').click(startSlideshow); $( '.pp_close, .pp_overlay' ).click( stopSlideshow ); binded = true; } }, 300 );
        
    } ).prettyPhoto( {
        theme: 'dark_square',
	markup: '<div class="pp_pic_holder"> \
						<div class="pp_top"> \
							<div class="pp_left"></div> \
							<div class="pp_middle"></div> \
							<div class="pp_right"></div> \
						</div> \
						<div class="pp_content_container"> \
							<div class="pp_left"> \
							<div class="pp_right"> \
								<div class="pp_content"> \
									<div class="pp_fade"> \
										<a href="#" class="pp_expand" title="Expand the image">Expand</a> \
										<div class="pp_loaderIcon"></div> \
										<div class="pp_hoverContainer"> \
											<a class="pp_next" href="#">next</a> \
											<a class="pp_previous" href="#">previous</a> \
										</div> \
										<div id="pp_full_res"></div> \
										<div class="pp_details clearfix"> \
											<a class="pp_close" href="#">Close</a> \
										pp_overlay	<a href="#" id="slideshow" style="margin-right: 5px;"><img src="images/slideshowOn.png" alt="" /></a>\
											<p class="pp_description"></p> \
											<div class="pp_nav"> \
												<a href="#" class="pp_arrow_previous">Previous</a> \
												<p class="currentTextHolder">0/0</p> \
												<a href="#" class="pp_arrow_next">Next</a> \
											</div> \
										</div> \
									</div> \
								</div> \
							</div> \
							</div> \
						</div> \
						<div class="pp_bottom"> \
							<div class="pp_left"></div> \
							<div class="pp_middle"></div> \
							<div class="pp_right"></div> \
						</div> \
					</div> \
					<div class="pp_overlay"></div> \
					<div class="ppt"></div>',

    } );
    
} );

function startSlideshow() {
       if(startedSlide) {
           stopSlideshow();
       } else {
         startedSlide = true;
         interval = setInterval( function() {
	    if( !$('.pp_arrow_next').hasClass('disabled') &&  ( !slideBack || $('.pp_arrow_previous').hasClass('disabled') ) ) {
	        $('.pp_arrow_next').click();
		slideBack = false;
	    } else if( !$('.pp_arrow_previous').hasClass('disabled') && slideBack ) {
	        $('.pp_arrow_previous').click();
	    } else {
		$('.pp_arrow_previous').click();
		slideBack = true;
	    }
	  }, 5000 );
          $( '#slideshow img' ).attr('src', 'images/slideshowOff.png');
	}
	return false;
       
    } 

/*news */
$(function() {
return;
    $('.newsBox .more').click( function() {
        if($('#home').get().length>0) {
            return true;
        }
        $(this).parent().parent().find('.full').slideDown();
        $(this).css('display', 'none');
        $('.newsBox .back').css('display', 'block');
        return false;
    } );
    $('.newsBox .img a').click(function() {
        $(this).parent().parent().find('.more').click();
        return false;
    });
    $('.newsBox .back').each(function() {
        if($(this).parent().parent().hasClass('fullNews')) {
            return;
        }
        $(this).click( function() {
            $(this).hide();
            $(this).parent().parent().find('.more').css('display', 'block');
            $(this).parent().slideUp();
            return false;
        } )} );
});

/*
 * Contact Form
 */
$( function() {
    $('.txtinput, #searchForm .text').each( function() {
        $(this).attr('defaultText', ( $(this).hasClass('mess') ? $(this).text() : $(this).attr('value') )).focus( txtinputFocus ).blur( txtinputBlur );
    } );

} );
function txtinputFocus() {
    if($(this).hasClass('mess')) {
        if($(this).attr('defaultText') == $(this).text())
            $(this).text('');
    } else {
        if($(this).attr('defaultText') == $(this).attr('value'))
            $(this).attr('value','');

    }
}

function txtinputBlur() {
    if($(this).hasClass('mess')) {
        if($(this).attr('value') == '')
            $(this).text($(this).attr('defaultText'));
    } else {
        if($(this).attr('value') == '')
            $(this).attr('value', $(this).attr('defaultText') );

    }
}

$(  function() {
    $('#top img').css( 'opacity', 0 );
    setTimeout( function() {
        $( '#top img' ).animate({opacity: 1}, 1000);
    }, 600 );
    

});

$(function() {
    $('.polecamy .title').toggle( function() {
        var up = $(this).parent();
        up.find('.all').slideDown();
        up.stop().animate( {height: '193px'} ).addClass('polecamyActive');
        return false;
    }, function() {
        var up = $(this).parent();
        up.find('.all').slideUp();
        up.stop().animate( {height: '25px'}, 'normal', function() {
            $(this).removeClass('polecamyActive');
        } );
        return false;
    } );
});

/**
 * menu
 */
$( function() {
    //alert( $.client.os + ' ' + $.client.browser );
    if( $.client.os == 'Mac' || $.client.os == 'mac' || $.client.os == 'MAC' || $.client.browser == 'Safari' ) {
        $( '#menu > li > a' ).css( 'padding', '0px 31px' );
    }
    $('#menu li').hover( function() {
        $(this).find('> ul').stop().removeAttr('style').attr('style', '').slideDown('fast');
        $(this).find('> a').addClass('hover');
    }, function() {
        $(this).find('> ul').stop().slideUp('fast');
        $(this).find('> a').removeClass('hover');
    } );
} );

/**
* slideshow
 */
$( function() {
    $('#galery td div').hover( function() {
        var img = $(this).find('> a > img');
        var url = img.attr('src').split('_');
        $(this).append( '<div class="slide" style="left:' + (img.width()+20)  + 'px"><img width="300px" src="' + url[0] + '_' + url[1] + '_' + url[2] + '" />' + img.attr('alt') + '</div>' );
        $(this).find('.slide').click(slideShow).fadeIn();
    }, function() {
        $(this).find('.slide').remove();
    } );
} );

function slideShow() {
    $(this).parent().find('> a').click();
}
