function createCookie(name,value,days) {if (days) {var date = new Date();date.setTime(date.getTime()+(days*24*60*60*1000));var expires = "; expires="+date.toGMTString();}else var expires = "";document.cookie = name+"="+value+expires+"; path=/";}function readCookie(name) {var nameEQ = name + "=";var ca = document.cookie.split(';');for(var i=0;i < ca.length;i++) {var c = ca[i];while (c.charAt(0)==' ') c = c.substring(1,c.length);if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);}return null;}function eraseCookie(name) {createCookie(name,"",-1);}

var are_img = 0;


jQuery('.slideshow img').live('click', function(){
	my_src = jQuery(this).attr('src');
	my_src = my_src.replace('300','600');
	my_src = my_src.replace('400','800');
	jQuery.fancybox({
		
		
		'transitionIn'	: 'none',
		'transitionOut'	: 'none',
		
		'type'			: 'image',
		
		'href'			: my_src
		
		
	});

});


jQuery('.show_hyves_url').live('click', function(){
	my_url = escape(jQuery('.hyves_url').val());
	
	jQuery.ajax({
		type: "POST",
		   url: "/preview.php",
		   data: "unique_id="+my_id+"&url=" + my_url,
		   success: function(msg){
				jQuery('.hyves_url_div').html(msg);
		   }

	});
	
	
	return false;
});

jQuery(document).ready(function() {
	

	
	
	jQuery('.hyves').click(function(){
		my_id = jQuery(this).attr('id');
		jQuery.ajax({
			type: "POST",
			   url: "/preview.php",
			   data: "unique_id="+my_id,
			   success: function(msg){
				jQuery.fancybox(
					   msg,
						{
				        	'autoDimensions'	: false,
							'width'         	: 500,
							'height'        	: 500,
							'transitionIn'		: 'none',
							'transitionOut'		: 'none'
							
							
						}
					);
			   }

		});
		
		  return false;
	});
	
	
	jQuery.ajax({
		   url: "/update_new.php"
	});
	
	jQuery(".sort").change(function () {
		jQuery(".sort_form").submit();
	});
	
	jQuery("img.prod_img").click(function() {
		var new_src = jQuery(this).attr("src");
		
		jQuery("img.prod_big_img").fadeOut('fast', function() {
			jQuery("img.prod_big_img").attr({src: new_src}).fadeIn('fast');
		});
	});
	var name = "#floatMenu";
    var menuYloc = null;
	
    jQuery(document).ready(function(){
        menuYloc = parseInt(jQuery(name).css("top").substring(0,jQuery(name).css("top").indexOf("px")))
        jQuery(window).scroll(function () { 
        	if(jQuery(document).scrollTop() >= 150)
        			var offset = menuYloc+(jQuery(document).scrollTop()-150)+"px";
        	else
        		var offset = "0px";
            jQuery(name).animate({top:offset},{duration:500,queue:false});
        });
    }); 
	
	jQuery('input[title!=""]').hint();
	jQuery("a.article").fancybox(
			{
				'easingIn'				: 'easeOutBack',
				'easingOut'				: 'easeInBack',
				'hideOnContentClick'	: false

			}
	);
	jQuery(function() {
		jQuery("#tree").treeview({
			collapsed: true,
			animated: "medium",
			control:"#sidetreecontrol"			
		});
	});
	
	var clicked_menu_head;
	var speed = 300;
 
	jQuery('.menu_head').click(function() {
		clicked_menu_head = jQuery(this);
		if (clicked_menu_head.next().is(':visible')) {
			clicked_menu_head.next().slideUp();
			//clicked_menu_head.css({backgroundImage:"url(left.png)"});
		}
 
		// if clicked menu head is submenu, check if there are any submenus in it, then hide
		clicked_menu_head.next().find('p.menu_head').each(function () {
			jQuery(this).next().slideUp(speed);
			//jQuery(this).css({backgroundImage:"url(left.png)"});
		});
 
		parent_menu_head = clicked_menu_head.parents('div.menu_body').prev(clicked_menu_head.parents('div.menu_body').size()-1);
 
		if (clicked_menu_head.next('div.menu_body').is(':visible')) {
		} else clicked_menu_head.css(/*{backgroundImage:"url(down.png)"}*/).next('div.menu_body').slideDown(speed);
 
 
		jQuery('#firstpane').children('p').siblings('p').each(function() {
			// loop through each main menu, if not equal, hide all sub menu
			if (parent_menu_head.attr('id')) {
				if (parent_menu_head.attr('id') != jQuery(this).attr('id')) {
					jQuery(this).children('div.menu_body').slideUp(speed);
				}
			} else {
				if (clicked_menu_head.attr('id') != jQuery(this).attr('id')) {
					//jQuery(this).css({backgroundImage:"url(left.png)"})
					jQuery(this).next().slideUp(speed).find('p.menu_head').each(function() {
						jQuery(this).next().slideUp(speed);
					});
				}
			}
 
		});
	});
});

function pageselectCallback(page_index, jq){
    var new_content = jQuery('#hiddenresult div.result:eq('+page_index+')').clone();
    jQuery('#Searchresult').empty().append(new_content);
    createCookie('px',page_index,1);
    return false;
}

function initPagination() {
	var cpn = parseInt(readCookie('px'));
	cpn = !cpn ? 0 : cpn;
	
    var num_entries = jQuery('#hiddenresult div.result').length;
    
    if((cpn+1) > num_entries)
    	cpn = 0;	
    // Create pagination element
    jQuery("#Pagination").pagination(num_entries, {
        num_edge_entries: 2,
        num_display_entries: 8,
        callback: pageselectCallback,
        items_per_page:1,
        current_page: cpn
    });
}

jQuery(document).ready(function(){      
    initPagination();
});

	function slideSwitch() {
    var $active = jQuery('#slideshow IMG.active');

    if ( $active.length == 0 ) $active = jQuery('#slideshow IMG:last');

    var $next =  $active.next().length ? $active.next()
        : jQuery('#slideshow IMG:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
	}
	
	
	jQuery(document).ready(function() {
		if(are_img){
		// We only want these styles applied when javascript is enabled
		jQuery('div.navigation').css({'width' : '400px', 'float' : 'right'});
		jQuery('div.content_gal').css('display', 'block');

		// Initially set opacity on thumbs and add
		// additional styling for hover effect on thumbs
		var onMouseOutOpacity = 0.67;
		jQuery('#thumbs ul.thumbs li').opacityrollover({
			mouseOutOpacity:   onMouseOutOpacity,
			mouseOverOpacity:  1.0,
			fadeSpeed:         'fast',
			exemptionSelector: '.selected'
		});
		
		// Initialize Advanced Galleriffic Gallery
		var gallery = jQuery('#thumbs').galleriffic({
			delay:                     2500,
			numThumbs:                 12,
			preloadAhead:              10,
			enableTopPager:            true,
			enableBottomPager:         true,
			maxPagesToShow:            7,
			imageContainerSel:         '#slideshow',
			controlsContainerSel:      '#controls',
			captionContainerSel:       '#caption',
			loadingContainerSel:       '#loading',
			renderSSControls:          true,
			renderNavControls:         true,
			playLinkText:              '<img src="/images/play.png" alt="play"/>',
			pauseLinkText:             '<img src="/images/pauze.png" alt="pause"/>',
			prevLinkText:              '&lsaquo; vorige foto',
			nextLinkText:              'volgende foto &rsaquo;',
			nextPageLinkText:          'volgende &rsaquo;',
			prevPageLinkText:          '&lsaquo; vorige',
			enableHistory:             false,
			autoStart:                 true,
			syncTransitions:           true,
			defaultTransitionDuration: 900,
			onSlideChange:             function(prevIndex, nextIndex) {
				// 'this' refers to the gallery, which is an extension of $('#thumbs')
				this.find('ul.thumbs').children()
					.eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
					.eq(nextIndex).fadeTo('fast', 1.0);
			},
			onPageTransitionOut:       function(callback) {
				this.fadeTo('fast', 0.0, callback);
			},
			onPageTransitionIn:        function() {
				this.fadeTo('fast', 1.0);
			}
		});
		}
	});

