// jquery stuff
$(document).ready(function() {
	
	// stora produkt popupen
	$('.iteminfo_qtip').each(function() {
		itemid = $(this).attr('rel');
		$(this).qtip( {
			show: { delay: 50 },
			hide: { when: 'mouseout', fixed: true },
			content: {
				url: 'iteminfo.php',
				data: { itemid: itemid },
				method: 'get',
				prerender: true
			},
			position: {
				corner: {
					tooltip: 'leftMiddle',
					target: 'rightMiddle'
				},
				adjust: {
					x: 0,
					screen: false
				}
			},
			style: {
				tip: 'leftMiddle',
				name: 'light',
				width: 350,
				padding: 20,
				border: {
					width: 5,
					color: '#555'
				}
			}
		});
	});
	
	// popup för produktbild
	$('.itemimage_qtip').each(function() {
		itemid = $(this).attr('rel');
		$(this).qtip( {
			show: { delay: 50 },
			content: {
				url: 'iteminfo.php',
				data: { itemid: itemid, type: 1},
				method: 'get'
			},
			position: {
				corner: {
					tooltip: 'leftMiddle',
					target: 'rightMiddle'
				},
				adjust: {
					x: 0,
					screen: false
				}
			},
			style: {
				tip: 'leftMiddle',
				name: 'light',
				width: 270,
				padding: 5,
				border: {
					width: 5,
					color: '#555'
				}
			}
		});
	});
	
	// videolista: produktlänk
	//$('.horizlist2 li').each(function() {
	$('.videolist li').each(function() {
		itemno = $(this).find('a').attr('rel');
		if(itemno != "") {
			$(this).find('a').addClass('title');
			$(this).append('<a href="viewitem.php?itemid=' + itemno + '" title="Till produkten" class="link">&nbsp;</a>');
			$(this).append('<div class="clear"></div>');
		}
	});
	
	// popup för köpråd
	$('.advise_popup').each(function() {
		advise_id = $(this).attr('rel');
		$(this).qtip({
			show: { delay: 50 },
			hide: { when: 'mouseout', fixed: true },
			content: {
				url: 'adviseinfo.php',
				data: { id: advise_id },
				method: 'get',
				prerender: true
			},
			position: {
				corner: {
					tooltip: 'leftMiddle',
					target: 'rightMiddle'
				},
				adjust: {
					x: 0,
					screen: false
				}
			},
			style: {
				tip: 'leftMiddle',
				name: 'light',
				width: 370,
				padding: 20,
				border: {
					width: 5,
					color: '#555'
				}
			}
		});
	});
	
	$('.slideshow').cycle({
		fx: 'fade'
	});
	
	// Videolinks
	$('.wp_content .videolink').each(function() {
		video = $(this).click(function(e) { e.preventDefault(); }).attr('href');
		$(this).attr('onClick', "return PlayVideo2(player, '" + video + "');");
	});
	
	// Ordlista
	$(".item_info .wordlist, .wp_content .wordlist").each(function() {
		$(this).qtip( {
			show: { delay: 50 },
			content: {
				url: 'dictionary.php',
				data: { q: $(this).text() },
				method: 'get'
			},
			position: {
				corner: {
					tooltip: 'leftBottom',
					target: 'rightMiddle'
				}
			},
			style: {
				tip: 'leftBottom',
				name: 'cream',
				width: 270
			}
		});
	});

	$('.order_mb_message').each(function() {
		$(this).qtip( {
			show: { delay: 50 },
			content: {
				url: 'orderinfo.php',
				data: { id: $(this).attr('rel'), info: 'mb_message' },
				method: 'get'
			},
			position: {
				corner: {
					tooltip: 'leftBottom',
					target: 'rightMiddle'
				}
			},
			style: {
				tip: 'leftBottom',
				name: 'cream',
				width: 270
			}
		});
	});
});

// Kontrollerar köpvillkor
function ProcessCheckoutForm()
{
	if($("#kopvillkor").is(":checked")) {
		return true;
	} else {
		alert("Du måste godkänna köpvillkoren.");
		return false;
	}
}


function OpenPopupWindow(url, width, height)
{
	popwin = window.open(url, '', 'width='+width+',height='+height+',status=no,menubar=yes,titlebar=yes,scrollbars=yes');
	//popwin = window.open(url, '', 'width='+width+',height='+height+',status=no,menubar=no,scrollbars=no,resizable=no,titlebar=no,dependent=yes,left=' + w + ',top=' + h + '');
}

function PlayVideo(player, sVideo)
{
	player.sendEvent('LOAD', 'filmer/' + sVideo);
	player.sendEvent('PLAY');
}

function PlayVideo2(player, sVideo)
{
	player.sendEvent('LOAD', '/jwplayer/filmer/' + sVideo);
	player.sendEvent('PLAY');
	return false;
}

function SetActiveVideoTab(sTabId)
{
	var videoTabs = new Array();
	videoTabs[0] = "video_list_1";
	videoTabs[1] = "video_list_2";
	videoTabs[2] = "video_list_3";
	
	for(i=0;i<videoTabs.length;i++)
	{
		if(sTabId == videoTabs[i]) {
			document.getElementById(sTabId).style.display = 'block';
//			alert(document.getElementById(sTabId+'_tab').className); // = 'video_tab selected';
//			alert(document.getElementById(sTabId+'_tab'));
		}
		else {
			var el = document.getElementById(videoTabs[i]);
			el.style.display = 'none';
			
		}
	}
}

function ToggleNFF()
{
	var NFF = document.getElementById('NotifyFriendFormLayer');

	if(NFF.style.display != 'block')
		NFF.style.display = 'block';
	else
		NFF.style.display = 'none';
	
	return false;
}

function tabSwitch_2(active, number, tab_prefix, content_prefix) {  
    
    for (var i=1; i < number+1; i++) {  
      document.getElementById(content_prefix+i).style.display = 'none';  
      document.getElementById(tab_prefix+i).className = '';  
    }  
    document.getElementById(content_prefix+active).style.display = 'block';  
    document.getElementById(tab_prefix+active).className = 'active';      
      
}  
