﻿$(function(){
	
	var searchTxt =  $( "#ss-phrase" ).attr( "rel" );
	$( "#ss-phrase" ).val( searchTxt );
	
	$( "#ss-phrase" ).focus(function() {
		$(this).val( '' );
	});
	
	$( "#ss-phrase" ).blur(function() {
		if( $(this).val() == '' )
			$( this ).val( searchTxt );
	});
	
	var openTxt = $( "ul.glossary span" ).eq(0).text() || $( "ul.faq span" ).eq(0).text();
	var closeTxt = $( "ul.glossary span" ).eq(0).attr( "rel" ) || $( "ul.faq span" ).eq(0).attr( "rel" );
	 
	 $( "ul.glossary span, ul.faq span" ).toggle(function(){
		 $( this ).text( closeTxt );
		 $( this ).parent().next().slideDown( '200' );
	 }, function(){
		 $( this ).text( openTxt );
		 $( this ).parent().next().slideUp( '200' );
	 });
	 
	$( '#model table tr.info' ).fancybox({
		ajax: { type: "POST", cache: false, url: $( this ).attr( "href" ) },
		padding: 0,
		titleShow: false
	});
	
	$( 'a.info' ).fancybox({
		ajax: { type: "POST", cache: false },
		padding:0,
		titleShow: false
	});
	
	$( 'a.fancy' ).fancybox({
		ajax:{cache: false},
		padding:0,
		titleShow: false
	});
		
	$( 'a.query' ).fancybox({
		ajax: { type: "POST", cache: false },
		padding:0,
		titleShow: false,
		href: ( $( "#notebook li" ).size() < 1 ) ? url + 'ajax/query/5' : url + 'ajax/query/0'	
	});		
	
	$('#thumbnails li').each(function(index) {
	  $( this ).click(function(){
	    $( "#large-image li.active" ).removeClass( 'active' );
      $( "#large-image li" ).eq( index ).addClass( 'active' );
	  });
  });
	
	$( "#notebook li span" ).click(function(){
		if( confirm( 'Czy chcesz usunąć wybrany produkt z notesu?' ))		
			var id = this.getAttribute( "rel" );
			$.ajax({ 
				cache: false,
				url: url + "ajax/remove_product/" + id,
				success: function( msg ) {					
					$( "#notebook ul" ).html( msg );			
					$( "#notebook ul" ).effect( "highlight", { color: '#F9EED3' }, 50);	
					$( "#m_" + id ).removeClass( 'added' );
				}
			});			
		return false;
	});
	
	$( "#model .notebook" ).click(function(){		
		var btn = this;
		var rel = this.getAttribute( "rel" );
		$( "#model .tbl" ).append( '<div class="loading"></div>' );
		if( $( btn ).hasClass( 'added' )) {	
			$.ajax({
				cache: false,
			  url: url + "ajax/remove_product/" + rel,			  
			  success: function( msg ){
					$( btn ).removeClass( 'added' );	
					$( "#model .tbl .loading" ).remove();
					$( "#notebook ul" ).html( msg );
					$( "#notebook ul" ).effect( "highlight", { color: '#F9EED3' }, 300);
			  }
			});	
		} else {				
			$.ajax({
				cache: false,
			  url: url + "ajax/add_product/" + this.getAttribute( "rel" ),			  
			  success: function( msg ){
					$( btn ).addClass( 'added' );
					$( "#model .tbl .loading" ).remove();
					$( "#notebook ul" ).html( msg );
					$( "#notebook ul" ).effect( "highlight", { color: '#F9EED3' }, 50);
			  }
			});		
		}
		return false;
	});
	
	$( "#slides .slides_container" ).jCarouselLite({
    btnNext: "#slides .next",
    btnPrev: "#slides .prev",
    visible: 1,
    easing: "easeOutQuad",
    speed: 450,
    btnGo: ".pagination"
	});
	
	$( "#thumbnails div" ).jCarouselLite({
    btnNext: "#thumbnails .next",
    btnPrev: "#thumbnails .prev",
    visible: 3,
    easing: "easeOutQuad",
    speed: 300,
    vertical: true,
    circular: false
	});
	
	$( ".notes" ).jCarouselLite({
    visible: 1,
    easing: "easeOutQuad",
    speed: 700,
    vertical: true,
    auto: 15000
	});
		
});



